Sleep to make sure Flask is ready for startup tasks

This commit is contained in:
deathbybandaid 2020-12-16 08:42:06 -05:00
parent 0e2da84138
commit 1f111f9c8f

View File

@ -52,13 +52,6 @@ def run(settings, logger, db, script_dir, fHDHR_web, origin, alternative_epg):
if settings.dict["main"]["thread_method"] in ["multiprocessing", "threading"]: if settings.dict["main"]["thread_method"] in ["multiprocessing", "threading"]:
fhdhr_web.start() fhdhr_web.start()
# Perform some actions now that HTTP Server is running, but don't wait for response
# Hit EPG Update API URL without waiting
try:
fhdhr.web.session.get("%s/api/startup_tasks" % (fhdhr.api.base))
except fhdhr.web.exceptions.ReadTimeout:
pass
if settings.dict["fhdhr"]["discovery_address"]: if settings.dict["fhdhr"]["discovery_address"]:
fhdhr.logger.info("SSDP Server Starting") fhdhr.logger.info("SSDP Server Starting")
if settings.dict["main"]["thread_method"] in ["multiprocessing"]: if settings.dict["main"]["thread_method"] in ["multiprocessing"]:
@ -69,7 +62,7 @@ def run(settings, logger, db, script_dir, fHDHR_web, origin, alternative_epg):
fhdhr_ssdp.start() fhdhr_ssdp.start()
if settings.dict["epg"]["method"]: if settings.dict["epg"]["method"]:
fhdhr.logger.info("EPG Update Starting") fhdhr.logger.info("EPG Update Thread Starting")
if settings.dict["main"]["thread_method"] in ["multiprocessing"]: if settings.dict["main"]["thread_method"] in ["multiprocessing"]:
fhdhr_epg = multiprocessing.Process(target=fhdhr.device.epg.run) fhdhr_epg = multiprocessing.Process(target=fhdhr.device.epg.run)
elif settings.dict["main"]["thread_method"] in ["threading"]: elif settings.dict["main"]["thread_method"] in ["threading"]:
@ -77,6 +70,18 @@ def run(settings, logger, db, script_dir, fHDHR_web, origin, alternative_epg):
if settings.dict["main"]["thread_method"] in ["multiprocessing", "threading"]: if settings.dict["main"]["thread_method"] in ["multiprocessing", "threading"]:
fhdhr_epg.start() fhdhr_epg.start()
# Perform some actions now that HTTP Server is running, but don't wait for response
# Hit EPG Update API URL without waiting
fhdhr.logger.info("Waiting 3 seconds to send startup tasks trigger.")
time.sleep(3)
try:
fhdhr.web.session.get("%s/api/startup_tasks" % (fhdhr.api.base))
except fhdhr.web.exceptions.ReadTimeout:
pass
except fhdhr.web.exceptions.ConnectionError as e:
fhdhr.logger.warning("Startup tasks failed: %s" % e)
pass
# wait forever # wait forever
while True: while True:
time.sleep(3600) time.sleep(3600)