From ea8537ac71c9d6f20ca0a3c71887f2a199173a9f Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Fri, 23 Jan 2015 10:16:54 -0500 Subject: [PATCH] Adjust the behavior of the cancel action For pending and waiting jobs this should set the cancel status immediately. For running jobs it should just set the cancel flag and let the running job set the cancelled status itself during its cancelation procedure. This also prevents a race condition where the task manager will start dependent jobs before realizing the status is cancelled. --- awx/main/models/unified_jobs.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/awx/main/models/unified_jobs.py b/awx/main/models/unified_jobs.py index 4486dc88c5..afe2dbf057 100644 --- a/awx/main/models/unified_jobs.py +++ b/awx/main/models/unified_jobs.py @@ -783,8 +783,11 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique if self.can_cancel: if not self.cancel_flag: self.cancel_flag = True - self.status = 'canceled' - self.save(update_fields=['cancel_flag', 'status']) + cancel_fields = ['cancel_flag'] + if self.status in ('pending', 'waiting'): + self.status = 'canceled' + cancel_fields.append('status') + self.save(update_fields=cancel_fields) self.socketio_emit_status("canceled") if settings.BROKER_URL.startswith('amqp://'): self._force_cancel()