From c3d7ef2ec4e073d74e4c7ae31b014c743969bd37 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 7 Aug 2015 13:14:14 -0400 Subject: [PATCH] Only start workers once setup is complete on the registry Fixes #326 --- workers/worker.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/workers/worker.py b/workers/worker.py index ac30fb5cf..a9ea5d219 100644 --- a/workers/worker.py +++ b/workers/worker.py @@ -53,8 +53,21 @@ class Worker(object): self._operations.append((_operation_func, operation_sec)) + def _setup_and_wait_for_shutdown(self): + signal.signal(signal.SIGTERM, self.terminate) + signal.signal(signal.SIGINT, self.terminate) + + while not self._stop.wait(1): + pass + def start(self): logging.config.fileConfig('conf/logging.conf', disable_existing_loggers=False) + + if not app.config.get('SETUP_COMPLETE', False): + logger.info('Product setup is not yet complete; skipping worker startup') + self._setup_and_wait_for_shutdown() + return + logger.debug('Scheduling worker.') soon = datetime.now() + timedelta(seconds=.001) @@ -64,11 +77,8 @@ class Worker(object): self._sched.add_job(operation_func, 'interval', seconds=operation_sec, start_date=soon, max_instances=1) - signal.signal(signal.SIGTERM, self.terminate) - signal.signal(signal.SIGINT, self.terminate) - while not self._stop.wait(1): - pass + self._setup_and_wait_for_shutdown() logger.debug('Waiting for running tasks to complete.') self._sched.shutdown()