Force connections to close when running overnight task

in case the task involves rebuilding current app DB
This commit is contained in:
Lance Edgar 2023-11-21 12:42:40 -06:00
parent d73e107d67
commit 6a1d7af1bf

View file

@ -185,7 +185,14 @@ class LuigiHandler(GenericHandler):
but do not actually run it.
"""
appdir = self.config.appdir()
env = {'PYTHONPATH': appdir}
# must preserve existing environ, but also add some things to it
env = dict(os.environ)
if 'PYTHONPATH' in env:
env['PYTHONPATH'] += os.pathsep + appdir
else:
env['PYTHONPATH'] = appdir
if keep_config:
env['RATTAIL_CONFIG_FILES'] = os.pathsep.join(self.config.files_read)
else:
@ -255,6 +262,18 @@ class LuigiHandler(GenericHandler):
log.debug("dry-run mode, so aborting")
return
# TODO: most overnight tasks can run okay, but occasionally we
# need an overnight task to rebuild the current app DB - i.e.
# drop the DB and re-clone from production. in these cases we
# cannot afford to have lingering connections to the current
# DB or else dropping it may fail. so our fix for now, is to
# foribly recreate the connection pool for all overnight task
# runs. would be nice to be more selective but this seems to
# work okay for now...
pool = self.config.rattail_engine.pool
pool.dispose()
self.config.rattail_engine.pool = pool.recreate()
# run command in subprocess
curdir = os.getcwd()
try: