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()