mirror of
https://github.com/ansible/awx.git
synced 2026-03-06 03:01:06 -03:30
task manager using messages
* First pass, adapt singleton task manager to process messages and run jobs based on events instead of a busy loop. * Still need to make message handing run in celery, not in a consumption loop
This commit is contained in:
@@ -31,6 +31,9 @@ except:
|
||||
# Pexpect
|
||||
import pexpect
|
||||
|
||||
# Kombu
|
||||
from kombu import Connection, Exchange, Queue, Producer
|
||||
|
||||
# Celery
|
||||
from celery import Task, task
|
||||
from celery.signals import celeryd_init
|
||||
@@ -202,6 +205,18 @@ def _send_notification_templates(instance, status_str):
|
||||
for n in all_notification_templates],
|
||||
job_id=instance.id)
|
||||
|
||||
|
||||
def _send_job_complete_msg(instance):
|
||||
connection = Connection(settings.BROKER_URL)
|
||||
exchange = Exchange(settings.SCHEDULER_QUEUE, type='topic')
|
||||
producer = Producer(connection)
|
||||
producer.publish({ 'job_id': instance.id, 'msg_type': 'job_complete' },
|
||||
serializer='json',
|
||||
compression='bzip2',
|
||||
exchange=exchange,
|
||||
declare=[exchange],
|
||||
routing_key='scheduler.job.complete')
|
||||
|
||||
@task(bind=True, queue='default')
|
||||
def handle_work_success(self, result, task_actual):
|
||||
instance = UnifiedJob.get_instance_by_type(task_actual['type'], task_actual['id'])
|
||||
@@ -210,6 +225,8 @@ def handle_work_success(self, result, task_actual):
|
||||
|
||||
_send_notification_templates(instance, 'succeeded')
|
||||
|
||||
_send_job_complete_msg(instance)
|
||||
|
||||
@task(bind=True, queue='default')
|
||||
def handle_work_error(self, task_id, subtasks=None):
|
||||
print('Executing error task id %s, subtasks: %s' %
|
||||
@@ -238,6 +255,9 @@ def handle_work_error(self, task_id, subtasks=None):
|
||||
|
||||
if first_instance:
|
||||
_send_notification_templates(first_instance, 'failed')
|
||||
|
||||
if first_instance:
|
||||
_send_job_complete_msg(first_instance)
|
||||
|
||||
@task(queue='default')
|
||||
def update_inventory_computed_fields(inventory_id, should_update_hosts=True):
|
||||
|
||||
Reference in New Issue
Block a user