diff --git a/etc/sample_stacktach_worker_config.json b/etc/sample_stacktach_worker_config.json index 5fea92a..e33ad9e 100644 --- a/etc/sample_stacktach_worker_config.json +++ b/etc/sample_stacktach_worker_config.json @@ -6,7 +6,8 @@ "rabbit_port": 5672, "rabbit_userid": "rabbit", "rabbit_password": "rabbit", - "rabbit_virtual_host": "/" + "rabbit_virtual_host": "/", + "exit_on_exception": true }, { "name": "east_coast.prod.cell1", @@ -15,6 +16,7 @@ "rabbit_port": 5672, "rabbit_userid": "rabbit", "rabbit_password": "rabbit", - "rabbit_virtual_host": "/" + "rabbit_virtual_host": "/", + "exit_on_exception": false }] } diff --git a/worker/worker.py b/worker/worker.py index db05257..a325f31 100644 --- a/worker/worker.py +++ b/worker/worker.py @@ -134,6 +134,11 @@ class NovaConsumer(kombu.mixins.ConsumerMixin): def continue_running(): return True +def exit_or_sleep(exit=False): + if exit_on_exception: + sys.exit(1q) + else: + time.sleep(5) def run(deployment_config): name = deployment_config['name'] @@ -170,11 +175,11 @@ def run(deployment_config): LOG.error("!!!!Exception!!!!") LOG.exception("name=%s, exception=%s. Reconnecting in 5s" % (name, e)) - time.sleep(5) + exit_or_sleep(deployment_config['exit_on_exception']) LOG.debug("Completed processing on '%s'" % name) except: LOG.error("!!!!Exception!!!!") e = sys.exc_info()[0] msg = "Uncaught exception: deployment=%s, exception=%s. Retrying in 5s" LOG.exception(msg % (name, e)) - time.sleep(5) + exit_or_sleep(deployment_config['exit_on_exception'])