Disallow creating callback jobs for the same host under the same job

template while another one is pending/waiting.  Update unit tests to
check for this scenario
This commit is contained in:
Matthew Jones
2014-12-11 11:50:01 -05:00
parent 2688f2c3cc
commit 60d8505fd3
3 changed files with 17 additions and 0 deletions

View File

@@ -1693,6 +1693,12 @@ class JobTemplateCallback(GenericAPIView):
return Response(data, status=status.HTTP_400_BAD_REQUEST)
limit = ':&'.join(filter(None, [job_template.limit, host.name]))
# NOTE: We limit this to one job waiting due to this: https://trello.com/c/yK36dGWp
if Job.objects.filter(status__in=['pending', 'waiting', 'running'], job_template=job_template,
limit=limit).count() > 0:
data = dict(msg='Host callback job already pending')
return Response(data, status=status.HTTP_400_BAD_REQUEST)
# Everything is fine; actually create the job.
with transaction.atomic():
job = job_template.create_job(limit=limit, launch_type='callback')