mirror of
https://github.com/ansible/awx.git
synced 2026-03-19 01:47:31 -02:30
add job cancel dependency information
* Inventory updates that are canceled and are dependencies of jobs result in the dependent job being canceled. This code adds a better description to job_explanation so that a job marked as canceled can be traced back to the inventory update that triggered this case.
This commit is contained in:
@@ -1277,10 +1277,20 @@ class InventoryUpdate(UnifiedJob, InventorySourceOptions, JobNotificationMixin):
|
|||||||
def get_notification_friendly_name(self):
|
def get_notification_friendly_name(self):
|
||||||
return "Inventory Update"
|
return "Inventory Update"
|
||||||
|
|
||||||
def cancel(self):
|
def _build_job_explanation(self):
|
||||||
res = super(InventoryUpdate, self).cancel()
|
if not self.job_explanation:
|
||||||
|
return 'Previous Task Canceled: {"job_type": "%s", "job_name": "%s", "job_id": "%s"}' % \
|
||||||
|
(self.model_to_str(), self.name, self.id)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_dependent_jobs(self):
|
||||||
|
return Job.objects.filter(dependent_jobs__in=[self.id])
|
||||||
|
|
||||||
|
def cancel(self, job_explanation=None):
|
||||||
|
|
||||||
|
res = super(InventoryUpdate, self).cancel(job_explanation=job_explanation)
|
||||||
if res:
|
if res:
|
||||||
map(lambda x: x.cancel(), Job.objects.filter(dependent_jobs__in=[self.id]))
|
map(lambda x: x.cancel(job_explanation=self._build_job_explanation()), self.get_dependent_jobs())
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -633,10 +633,10 @@ class Job(UnifiedJob, JobOptions, SurveyJobMixin, JobNotificationMixin):
|
|||||||
Canceling a job also cancels the implicit project update with launch_type
|
Canceling a job also cancels the implicit project update with launch_type
|
||||||
run.
|
run.
|
||||||
'''
|
'''
|
||||||
def cancel(self):
|
def cancel(self, job_explanation=None):
|
||||||
res = super(Job, self).cancel()
|
res = super(Job, self).cancel(job_explanation=job_explanation)
|
||||||
if self.project_update:
|
if self.project_update:
|
||||||
self.project_update.cancel()
|
self.project_update.cancel(job_explanation=job_explanation)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1025,7 +1025,7 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
|||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def cancel(self):
|
def cancel(self, job_explanation=None):
|
||||||
if self.can_cancel:
|
if self.can_cancel:
|
||||||
if not self.cancel_flag:
|
if not self.cancel_flag:
|
||||||
self.cancel_flag = True
|
self.cancel_flag = True
|
||||||
@@ -1033,6 +1033,9 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
|||||||
if self.status in ('pending', 'waiting', 'new'):
|
if self.status in ('pending', 'waiting', 'new'):
|
||||||
self.status = 'canceled'
|
self.status = 'canceled'
|
||||||
cancel_fields.append('status')
|
cancel_fields.append('status')
|
||||||
|
if job_explanation is not None:
|
||||||
|
self.job_explanation = job_explanation
|
||||||
|
cancel_fields.append('job_explanation')
|
||||||
self.save(update_fields=cancel_fields)
|
self.save(update_fields=cancel_fields)
|
||||||
self.websocket_emit_status("canceled")
|
self.websocket_emit_status("canceled")
|
||||||
if settings.BROKER_URL.startswith('amqp://'):
|
if settings.BROKER_URL.startswith('amqp://'):
|
||||||
|
|||||||
Reference in New Issue
Block a user