From 19c8fe915f7dcb49112aaba494c8786bd20d4e34 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Wed, 15 Jun 2016 12:08:17 -0400 Subject: [PATCH] Add a celery worker init task We'll use this task to perform any worker specific startup actions. Initially this is used to re-sync any Tower schedules on startup. --- awx/main/tasks.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 5a151acdc1..3f25d7edb2 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -33,6 +33,7 @@ import pexpect # Celery from celery import Task, task +from celery.signals import celeryd_init, worker_ready # Django from django.conf import settings @@ -67,6 +68,17 @@ Try upgrading OpenSSH or providing your private key in an different format. \ logger = logging.getLogger('awx.main.tasks') +@celeryd_init.connect +def celery_startup(conf=None, **kwargs): + # Re-init all schedules + # NOTE: Rework this during the Rampart work + logger.info("Syncing Tower Schedules") + for sch in Schedule.objects.all(): + try: + sch.update_computed_fields() + except Exception, e: + logger.error("Failed to rebuild schedule {}: {}".format(sch, e)) + @task() def send_notifications(notification_list, job_id=None): if not isinstance(notification_list, list):