commit
5b5b1d16b8
1 changed files with 15 additions and 4 deletions
|
@ -24,6 +24,7 @@ class Worker(object):
|
||||||
self._operations = []
|
self._operations = []
|
||||||
self._stop = Event()
|
self._stop = Event()
|
||||||
self._terminated = Event()
|
self._terminated = Event()
|
||||||
|
self._raven_client = None
|
||||||
|
|
||||||
if app.config.get('EXCEPTION_LOG_TYPE', 'FakeSentry') == 'Sentry':
|
if app.config.get('EXCEPTION_LOG_TYPE', 'FakeSentry') == 'Sentry':
|
||||||
worker_name = '%s:worker-%s' % (socket.gethostname(), self.__class__.__name__)
|
worker_name = '%s:worker-%s' % (socket.gethostname(), self.__class__.__name__)
|
||||||
|
@ -52,8 +53,21 @@ class Worker(object):
|
||||||
|
|
||||||
self._operations.append((_operation_func, operation_sec))
|
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):
|
def start(self):
|
||||||
logging.config.fileConfig('conf/logging.conf', disable_existing_loggers=False)
|
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.')
|
logger.debug('Scheduling worker.')
|
||||||
|
|
||||||
soon = datetime.now() + timedelta(seconds=.001)
|
soon = datetime.now() + timedelta(seconds=.001)
|
||||||
|
@ -63,11 +77,8 @@ class Worker(object):
|
||||||
self._sched.add_job(operation_func, 'interval', seconds=operation_sec,
|
self._sched.add_job(operation_func, 'interval', seconds=operation_sec,
|
||||||
start_date=soon, max_instances=1)
|
start_date=soon, max_instances=1)
|
||||||
|
|
||||||
signal.signal(signal.SIGTERM, self.terminate)
|
|
||||||
signal.signal(signal.SIGINT, self.terminate)
|
|
||||||
|
|
||||||
while not self._stop.wait(1):
|
self._setup_and_wait_for_shutdown()
|
||||||
pass
|
|
||||||
|
|
||||||
logger.debug('Waiting for running tasks to complete.')
|
logger.debug('Waiting for running tasks to complete.')
|
||||||
self._sched.shutdown()
|
self._sched.shutdown()
|
||||||
|
|
Reference in a new issue