Prevent blocking when sending files to the i2

This commit is contained in:
April 2022-11-13 17:08:26 -07:00
parent 7727cdc23d
commit 2936a64cff
No known key found for this signature in database
GPG Key ID: 17A9A017FAA4DE5E
14 changed files with 40 additions and 27 deletions

View File

@ -88,6 +88,7 @@ def getTime(timestamp) -> str:
return str(time) return str(time)
async def collect(radarType: str): async def collect(radarType: str):
loop = asyncio.get_running_loop()
ts = await getValidTimestamps(radarType) ts = await getValidTimestamps(radarType)
frames = await downloadRadarFrames(radarType, ts) frames = await downloadRadarFrames(radarType, ts)
@ -99,4 +100,4 @@ async def collect(radarType: str):
if radarType == "satrad": if radarType == "satrad":
commands.append( '<MSG><Exec workRequest="storePriorityImage(FileExtension=.tiff,File={0},Location=US,ImageType=SatRad,IssueTime=' + getTime(ts[i]) + ')"/></MSG>' ) commands.append( '<MSG><Exec workRequest="storePriorityImage(FileExtension=.tiff,File={0},Location=US,ImageType=SatRad,IssueTime=' + getTime(ts[i]) + ')"/></MSG>' )
bit.sendFile([frames[i]], [commands[i]], 1, 0) await loop.run_in_executor(bit.sendFile([frames[i]], [commands[i]], 1, 0))

View File

@ -7,7 +7,7 @@ import records.LFRecord as LFR
import gzip import gzip
from os import remove from os import remove
import xml.dom.minidom import xml.dom.minidom
import aiohttp, aiofiles import aiohttp, aiofiles, asyncio
l = logging.getLogger(__name__) l = logging.getLogger(__name__)
coloredlogs.install() coloredlogs.install()
@ -43,6 +43,7 @@ async def getData(coopId, geocode):
await f.close() await f.close()
async def makeRecord(): async def makeRecord():
loop = asyncio.get_running_loop()
l.info("Writing AchesAndPains record.") l.info("Writing AchesAndPains record.")
header = '<Data type="AchesAndPains">' header = '<Data type="AchesAndPains">'
@ -73,7 +74,7 @@ async def makeRecord():
file = "./.temp/AchesAndPains.gz" file = "./.temp/AchesAndPains.gz"
command = '<MSG><Exec workRequest="storeData(File={0},QGROUP=__AchesAndPains__,Feed=AchesAndPains)" /><GzipCompressedMsg fname="AchesAndPains" /></MSG>' command = '<MSG><Exec workRequest="storeData(File={0},QGROUP=__AchesAndPains__,Feed=AchesAndPains)" /><GzipCompressedMsg fname="AchesAndPains" /></MSG>'
bit.sendFile([file], [command], 1, 0) await loop.run_in_executor(bit.sendFile([file], [command], 1, 0))
remove('./.temp/AchesAndPains.i2m') remove('./.temp/AchesAndPains.i2m')
remove('./.temp/AchesAndPains.gz') remove('./.temp/AchesAndPains.gz')

View File

@ -4,7 +4,7 @@ import os
import shutil import shutil
import xml.dom.minidom import xml.dom.minidom
import logging,coloredlogs import logging,coloredlogs
import aiohttp, aiofiles import aiohttp, aiofiles, asyncio
l = logging.getLogger(__name__) l = logging.getLogger(__name__)
coloredlogs.install() coloredlogs.install()
@ -46,6 +46,7 @@ async def getData(epaId, zipcode):
await f.close() await f.close()
async def writeData(): async def writeData():
loop = asyncio.get_running_loop()
useData = False useData = False
workingEpaIds = [] workingEpaIds = []
@ -93,7 +94,7 @@ async def writeData():
comand = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__AirQuality__,Feed=AirQuality)" /><GzipCompressedMsg fname="AirQuality" /></MSG>') comand = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__AirQuality__,Feed=AirQuality)" /><GzipCompressedMsg fname="AirQuality" /></MSG>')
numFiles = len(files) numFiles = len(files)
bit.sendFile(files, commands, numFiles, 0) await loop.run_in_executor(bit.sendFile(files, commands, numFiles, 0))
os.remove("./.temp/AirQuality.i2m") os.remove("./.temp/AirQuality.i2m")
os.remove("./.temp/AirQuality.gz") os.remove("./.temp/AirQuality.gz")

View File

@ -4,7 +4,7 @@ import os
import shutil import shutil
import xml.dom.minidom import xml.dom.minidom
import logging,coloredlogs import logging,coloredlogs
import aiohttp, aiofiles import aiohttp, aiofiles, asyncio
import sys import sys
sys.path.append("./py2lib") sys.path.append("./py2lib")
@ -48,6 +48,7 @@ async def getData(airport):
await f.close() await f.close()
async def writeData(): async def writeData():
loop = asyncio.get_running_loop()
useData = False useData = False
airportsWithDelays = [] airportsWithDelays = []
@ -93,7 +94,7 @@ async def writeData():
comand = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__AirportDelays__,Feed=AirportDelays)" /><GzipCompressedMsg fname="AirportDelays" /></MSG>') comand = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__AirportDelays__,Feed=AirportDelays)" /><GzipCompressedMsg fname="AirportDelays" /></MSG>')
numFiles = len(files) numFiles = len(files)
bit.sendFile(files, commands, numFiles, 0) await loop.run_in_executor(bit.sendFile(files, commands, numFiles, 0))
os.remove("./.temp/AirportDelays.i2m") os.remove("./.temp/AirportDelays.i2m")
os.remove("./.temp/AirportDelays.gz") os.remove("./.temp/AirportDelays.gz")

View File

@ -9,7 +9,7 @@ import xml.dom.minidom
import shutil import shutil
import gzip import gzip
import logging,coloredlogs import logging,coloredlogs
import aiofiles, aiohttp import aiohttp, aiofiles, asyncio
import sys import sys
@ -324,6 +324,7 @@ async def getAlerts(location):
async def makeRecord(): async def makeRecord():
loop = asyncio.get_running_loop()
global k global k
# The BERecord XML doesn't need to be written if there's no alerts. # The BERecord XML doesn't need to be written if there's no alerts.

View File

@ -6,7 +6,7 @@ import os
import shutil import shutil
import xml.dom.minidom import xml.dom.minidom
import logging,coloredlogs import logging,coloredlogs
import aiohttp, aiofiles import aiohttp, aiofiles, asyncio
sys.path.append("./py2lib") sys.path.append("./py2lib")
sys.path.append("./Util") sys.path.append("./Util")
@ -52,6 +52,7 @@ async def getData(coopId, geocode):
async def makeDataFile(): async def makeDataFile():
loop = asyncio.get_running_loop()
l.info("Writing a Breathing forecast record.") l.info("Writing a Breathing forecast record.")
header = '<Data type="Breathing">' header = '<Data type="Breathing">'
footer = '</Data>' footer = '</Data>'
@ -85,7 +86,7 @@ async def makeDataFile():
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__Breathing__,Feed=Breathing)" /><GzipCompressedMsg fname="Breathing" /></MSG>') command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__Breathing__,Feed=Breathing)" /><GzipCompressedMsg fname="Breathing" /></MSG>')
numFiles = len(files) numFiles = len(files)
bit.sendFile(files, commands, numFiles, 0) await loop.run_in_executor(bit.sendFile(files, commands, numFiles, 0))
os.remove("./.temp/Breathing.i2m") os.remove("./.temp/Breathing.i2m")
os.remove("./.temp/Breathing.gz") os.remove("./.temp/Breathing.gz")

View File

@ -6,8 +6,7 @@ import os
import shutil import shutil
import xml.dom.minidom import xml.dom.minidom
import logging,coloredlogs import logging,coloredlogs
import aiofiles import aiohttp, aiofiles, asyncio
import aiohttp
import sys import sys
sys.path.append("./py2lib") sys.path.append("./py2lib")
@ -55,6 +54,7 @@ async def getData(tecci, zipCode):
async def makeDataFile(): async def makeDataFile():
loop = asyncio.get_running_loop()
l.info("Writing a CurrentObservations record.") l.info("Writing a CurrentObservations record.")
header = '<Data type="CurrentObservations">' header = '<Data type="CurrentObservations">'
footer = '</Data>' footer = '</Data>'
@ -92,7 +92,7 @@ async def makeDataFile():
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__CurrentObservations__,Feed=CurrentObservations)" /><GzipCompressedMsg fname="CurrentObservations" /></MSG>') command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__CurrentObservations__,Feed=CurrentObservations)" /><GzipCompressedMsg fname="CurrentObservations" /></MSG>')
numFiles = len(files) numFiles = len(files)
bit.sendFile(files, commands, numFiles, 0) await loop.run_in_executor(await loop.run_in_executor(bit.sendFile(files, commands, numFiles, 0)))
os.remove("./.temp/CurrentObservations.i2m") os.remove("./.temp/CurrentObservations.i2m")
os.remove("./.temp/CurrentObservations.gz") os.remove("./.temp/CurrentObservations.gz")

View File

@ -6,7 +6,7 @@ import os
import shutil import shutil
import xml.dom.minidom import xml.dom.minidom
import logging,coloredlogs import logging,coloredlogs
import aiofiles, aiohttp import aiohttp, aiofiles, asyncio
sys.path.append("./py2lib") sys.path.append("./py2lib")
sys.path.append("./Util") sys.path.append("./Util")
@ -53,6 +53,7 @@ async def getData(tecci, zipCode):
async def makeDataFile(): async def makeDataFile():
loop = asyncio.get_running_loop()
l.info("Writing a DailyForecast record.") l.info("Writing a DailyForecast record.")
header = '<Data type="DailyForecast">' header = '<Data type="DailyForecast">'
footer = '</Data>' footer = '</Data>'
@ -86,7 +87,7 @@ async def makeDataFile():
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__DailyForecast__,Feed=DailyForecast)" /><GzipCompressedMsg fname="DailyForecast" /></MSG>') command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__DailyForecast__,Feed=DailyForecast)" /><GzipCompressedMsg fname="DailyForecast" /></MSG>')
numFiles = len(files) numFiles = len(files)
bit.sendFile(files, commands, numFiles, 0) await loop.run_in_executor(bit.sendFile(files, commands, numFiles, 0))
os.remove("./.temp/DailyForecast.i2m") os.remove("./.temp/DailyForecast.i2m")
os.remove("./.temp/DailyForecast.gz") os.remove("./.temp/DailyForecast.gz")

View File

@ -7,7 +7,7 @@ import records.LFRecord as LFR
import gzip import gzip
from os import remove from os import remove
import xml.dom.minidom import xml.dom.minidom
import aiohttp, aiofiles import aiohttp, aiofiles, asyncio
l = logging.getLogger(__name__) l = logging.getLogger(__name__)
coloredlogs.install() coloredlogs.install()
@ -43,6 +43,7 @@ async def getData(coopId, geocode):
await f.close() await f.close()
async def makeRecord(): async def makeRecord():
loop = asyncio.get_running_loop()
l.info("Writing HeatingAndCooling record.") l.info("Writing HeatingAndCooling record.")
header = '<Data type="HeatingAndCooling">' header = '<Data type="HeatingAndCooling">'
@ -73,7 +74,7 @@ async def makeRecord():
file = "./.temp/HeatingAndCooling.gz" file = "./.temp/HeatingAndCooling.gz"
command = '<MSG><Exec workRequest="storeData(File={0},QGROUP=__HeatingAndCooling__,Feed=HeatingAndCooling)" /><GzipCompressedMsg fname="HeatingAndCooling" /></MSG>' command = '<MSG><Exec workRequest="storeData(File={0},QGROUP=__HeatingAndCooling__,Feed=HeatingAndCooling)" /><GzipCompressedMsg fname="HeatingAndCooling" /></MSG>'
bit.sendFile([file], [command], 1, 0) await loop.run_in_executor(bit.sendFile([file], [command], 1, 0))
remove('./.temp/HeatingAndCooling.i2m') remove('./.temp/HeatingAndCooling.i2m')
remove('./.temp/HeatingAndCooling.gz') remove('./.temp/HeatingAndCooling.gz')

View File

@ -5,7 +5,7 @@ import os
import shutil import shutil
import xml.dom.minidom import xml.dom.minidom
import logging,coloredlogs import logging,coloredlogs
import aiofiles, aiohttp, asyncio import aiohttp, aiofiles, asyncio, asyncio
import sys import sys
sys.path.append("./py2lib") sys.path.append("./py2lib")
@ -54,6 +54,7 @@ async def getData(tecci, zipCode):
async def makeDataFile(): async def makeDataFile():
loop = asyncio.get_running_loop()
l.info("Writing an HourlyForecast record.") l.info("Writing an HourlyForecast record.")
header = '<Data type="HourlyForecast">' header = '<Data type="HourlyForecast">'
footer = '</Data>' footer = '</Data>'
@ -88,7 +89,7 @@ async def makeDataFile():
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__HourlyForecast__,Feed=HourlyForecast)" /><GzipCompressedMsg fname="HourlyForecast" /></MSG>') command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__HourlyForecast__,Feed=HourlyForecast)" /><GzipCompressedMsg fname="HourlyForecast" /></MSG>')
numFiles = len(files) numFiles = len(files)
bit.sendFile(files, commands, numFiles, 0) await loop.run_in_executor(bit.sendFile(files, commands, numFiles, 0))
os.remove("./.temp/HourlyForecast.i2m") os.remove("./.temp/HourlyForecast.i2m")
os.remove("./.temp/HourlyForecast.gz") os.remove("./.temp/HourlyForecast.gz")

View File

@ -7,7 +7,7 @@ import records.LFRecord as LFR
import gzip import gzip
from os import remove from os import remove
import xml.dom.minidom import xml.dom.minidom
import aiohttp, aiofiles import aiohttp, aiofiles, asyncio
l = logging.getLogger(__name__) l = logging.getLogger(__name__)
coloredlogs.install() coloredlogs.install()
@ -43,6 +43,7 @@ async def getData(coopId, geocode):
await f.close() await f.close()
async def makeRecord(): async def makeRecord():
loop = asyncio.get_running_loop()
l.info("Writing MosquitoActivity record.") l.info("Writing MosquitoActivity record.")
header = '<Data type="MosquitoActivity">' header = '<Data type="MosquitoActivity">'
@ -73,7 +74,7 @@ async def makeRecord():
file = "./.temp/MosquitoActivity.gz" file = "./.temp/MosquitoActivity.gz"
command = '<MSG><Exec workRequest="storeData(File={0},QGROUP=__MosquitoActivity__,Feed=MosquitoActivity)" /><GzipCompressedMsg fname="MosquitoActivity" /></MSG>' command = '<MSG><Exec workRequest="storeData(File={0},QGROUP=__MosquitoActivity__,Feed=MosquitoActivity)" /><GzipCompressedMsg fname="MosquitoActivity" /></MSG>'
bit.sendFile([file], [command], 1, 0) await loop.run_in_executor(bit.sendFile([file], [command], 1, 0))
remove('./.temp/MosquitoActivity.i2m') remove('./.temp/MosquitoActivity.i2m')
remove('./.temp/MosquitoActivity.gz') remove('./.temp/MosquitoActivity.gz')

View File

@ -6,7 +6,7 @@ import os
import shutil import shutil
import xml.dom.minidom import xml.dom.minidom
import logging, coloredlogs import logging, coloredlogs
import aiohttp, aiofiles import aiohttp, aiofiles, asyncio
sys.path.append("./py2lib") sys.path.append("./py2lib")
sys.path.append("./Util") sys.path.append("./Util")
@ -52,6 +52,7 @@ async def getData(pollenId, geocode):
async def makeDataFile(): async def makeDataFile():
loop = asyncio.get_running_loop()
l.info("Writing a PollenForecast record.") l.info("Writing a PollenForecast record.")
header = '<Data type="PollenForecast">' header = '<Data type="PollenForecast">'
footer = '</Data>' footer = '</Data>'
@ -85,7 +86,7 @@ async def makeDataFile():
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__PollenForecast__,Feed=PollenForecast)" /><GzipCompressedMsg fname="PollenForecast" /></MSG>') command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__PollenForecast__,Feed=PollenForecast)" /><GzipCompressedMsg fname="PollenForecast" /></MSG>')
numFiles = len(files) numFiles = len(files)
bit.sendFile(files, commands, numFiles, 0) await loop.run_in_executor(bit.sendFile(files, commands, numFiles, 0))
os.remove("./.temp/PollenForecast.i2m") os.remove("./.temp/PollenForecast.i2m")
os.remove("./.temp/PollenForecast.gz") os.remove("./.temp/PollenForecast.gz")

View File

@ -7,7 +7,7 @@ import records.LFRecord as LFR
import gzip import gzip
from os import remove from os import remove
import xml.dom.minidom import xml.dom.minidom
import aiohttp, aiofiles import aiohttp, aiofiles, asyncio
l = logging.getLogger(__name__) l = logging.getLogger(__name__)
coloredlogs.install() coloredlogs.install()
@ -48,6 +48,7 @@ async def getData(tideStation, geocode):
await f.close() await f.close()
async def makeRecord(): async def makeRecord():
loop = asyncio.get_running_loop()
if len(tideStations) < 1: if len(tideStations) < 1:
l.debug("Skipping TidesForecast -- No locations.") l.debug("Skipping TidesForecast -- No locations.")
return return
@ -82,7 +83,7 @@ async def makeRecord():
file = "./.temp/TidesForecast.gz" file = "./.temp/TidesForecast.gz"
command = '<MSG><Exec workRequest="storeData(File={0},QGROUP=__TidesForecast__,Feed=TidesForecast)" /><GzipCompressedMsg fname="TidesForecast" /></MSG>' command = '<MSG><Exec workRequest="storeData(File={0},QGROUP=__TidesForecast__,Feed=TidesForecast)" /><GzipCompressedMsg fname="TidesForecast" /></MSG>'
bit.sendFile([file], [command], 1, 0) await loop.run_in_executor(bit.sendFile([file], [command], 1, 0))
remove('./.temp/TidesForecast.i2m') remove('./.temp/TidesForecast.i2m')
remove('./.temp/TidesForecast.gz') remove('./.temp/TidesForecast.gz')

View File

@ -7,7 +7,7 @@ import records.LFRecord as LFR
import gzip import gzip
from os import remove from os import remove
import xml.dom.minidom import xml.dom.minidom
import aiohttp, aiofiles import aiohttp, aiofiles, asyncio
l = logging.getLogger(__name__) l = logging.getLogger(__name__)
coloredlogs.install() coloredlogs.install()
@ -42,6 +42,7 @@ async def getData(coopId, geocode):
await f.close() await f.close()
async def makeRecord(): async def makeRecord():
loop = asyncio.get_running_loop()
l.info("Writing WateringNeeds record.") l.info("Writing WateringNeeds record.")
header = '<Data type="WateringNeeds">' header = '<Data type="WateringNeeds">'
@ -72,7 +73,7 @@ async def makeRecord():
file = "./.temp/WateringNeeds.gz" file = "./.temp/WateringNeeds.gz"
command = '<MSG><Exec workRequest="storeData(File={0},QGROUP=__WateringNeeds__,Feed=WateringNeeds)" /><GzipCompressedMsg fname="WateringNeeds" /></MSG>' command = '<MSG><Exec workRequest="storeData(File={0},QGROUP=__WateringNeeds__,Feed=WateringNeeds)" /><GzipCompressedMsg fname="WateringNeeds" /></MSG>'
bit.sendFile([file], [command], 1, 0) await loop.run_in_executor(bit.sendFile([file], [command], 1, 0))
remove('./.temp/WateringNeeds.i2m') remove('./.temp/WateringNeeds.i2m')
remove('./.temp/WateringNeeds.gz') remove('./.temp/WateringNeeds.gz')