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.
This commit is contained in:
Matthew Jones 2016-06-15 12:08:17 -04:00
parent 69c994bd16
commit 19c8fe915f

View File

@ -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):