Skip to content

Commit 4b1cc69

Browse files
committed
Improve logging for starting jobs and test cleanup
1 parent 36a00ec commit 4b1cc69

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

awx/main/tasks/jobs.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,23 @@ def _wrapped(self, *args, **kwargs):
116116

117117
@task(on_duplicate='queue_one', bind=True, queue=get_task_queuename)
118118
def dispatch_waiting_jobs(binder):
119-
for uj in UnifiedJob.objects.filter(status='waiting', controller_node=settings.CLUSTER_HOST_ID).only('id', 'status', 'polymorphic_ctype', 'celery_task_id'):
119+
start_time = time.monotonic()
120+
job_id_list = []
121+
for uj in UnifiedJob.objects.filter(status='waiting', controller_node=settings.CLUSTER_HOST_ID).only('id', 'status', 'polymorphic_ctype', 'celery_task_id')[
122+
:25
123+
]:
120124
kwargs = uj.get_start_kwargs()
121125
if not kwargs:
122126
kwargs = {}
127+
job_id_list.append(uj.pk)
123128
binder.control('run', data={'task': serialize_task(uj._get_task_class()), 'args': [uj.id], 'kwargs': kwargs, 'uuid': uj.celery_task_id})
129+
if job_id_list:
130+
logger.info(f'Dispatching off waiting jobs {job_id_list}, in time {time.monotonic() - start_time}')
131+
# If this is a burst, the task manager may still be producing more jobs so reschedule
132+
if len(job_id_list) > 1:
133+
binder.control('run', data={'task': serialize_task(dispatch_waiting_jobs), 'args': [], 'kwargs': {}})
134+
else:
135+
logger.debug('No more waiting jobs to dispatch on this node')
124136

125137

126138
class BaseTask(object):

awx/main/tests/functional/test_bulk.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from uuid import uuid4
44

5+
from django.test import override_settings
6+
57
from awx.api.versioning import reverse
68

79
from awx.main.models.jobs import JobTemplate
@@ -98,10 +100,10 @@ def test_bulk_job_launch_queries(job_template, organization, inventory, project,
98100
inventory.save()
99101
jobs = [{'unified_job_template': jt.id, 'inventory': inventory.id} for _ in range(num_jobs)]
100102

101-
# This is not working, we need to figure that out if we want to include tests for more jobs
102-
# with mock.patch('awx.api.serializers.settings.BULK_JOB_MAX_LAUNCH', num_jobs + 1):
103-
with django_assert_max_num_queries(num_queries):
104-
bulk_job_launch_response = post(reverse('api:bulk_job_launch'), {'name': 'Bulk Job Launch', 'jobs': jobs}, normal_user, expect=201).data
103+
# Assure settings allow given number of jobs
104+
with override_settings(BULK_JOB_MAX_LAUNCH=num_jobs + 1):
105+
with django_assert_max_num_queries(num_queries):
106+
bulk_job_launch_response = post(reverse('api:bulk_job_launch'), {'name': 'Bulk Job Launch', 'jobs': jobs}, normal_user, expect=201).data
105107

106108
# Run task manager so the workflow job nodes actually spawn
107109
TaskManager().schedule()

0 commit comments

Comments
 (0)