Commit 49cec21b authored by Patrick van der Leer's avatar Patrick van der Leer
Browse files

Fixes background scheduler/blackhole processor

parent 74d7af4f
Pipeline #313 passed with stage
in 4 minutes and 36 seconds
......@@ -120,6 +120,7 @@ def configure_scheduler(app): # pragma: no cover
ext.scheduler.add_job(
func=process_blackhole_job,
kwargs={
"app": app,
"blackhole_path": app.config['BLACKHOLE_PATH']
},
trigger="interval",
......@@ -129,7 +130,6 @@ def configure_scheduler(app): # pragma: no cover
except Exception as e:
app.logger.error(str(e))
raise
ext.scheduler.start()
......
......@@ -151,9 +151,10 @@ def process_blackhole(blackhole_path):
yield saved, book_edition_file, file
def process_blackhole_job(blackhole_path):
def process_blackhole_job(app, blackhole_path):
if lock.acquire(blocking=False):
list(process_blackhole(os.path.abspath(blackhole_path)))
with app.app_context():
list(process_blackhole(os.path.abspath(blackhole_path)))
__all__ = (
......
......@@ -11,7 +11,7 @@ class Scheduler(BackgroundScheduler):
atexit.register(lambda: self.shutdown())
def start(self, *args, **kwargs):
if self._thread and not self._thread.is_alive():
if not self._thread or not self._thread.is_alive():
super().start(*args, **kwargs)
def shutdown(self, *args, **kwargs):
......
......@@ -16,4 +16,4 @@ class BlackHoleTestCase(MyTestCase, TestCase):
with open(path, "w+") as f:
f.write("1234")
process_blackhole_job(get_blackhole_path())
process_blackhole_job(self.app, get_blackhole_path())
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment