Merge pull request #331 from coreos-inc/queuefixes

Worker fixes
This commit is contained in:
Jake Moshenko 2015-08-07 15:37:54 -04:00
commit 5b5b1d16b8

View file

@ -24,6 +24,7 @@ class Worker(object):
self._operations = []
self._stop = Event()
self._terminated = Event()
self._raven_client = None
if app.config.get('EXCEPTION_LOG_TYPE', 'FakeSentry') == 'Sentry':
worker_name = '%s:worker-%s' % (socket.gethostname(), self.__class__.__name__)
@ -52,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)
@ -63,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()