1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Merge pull request #4445 from chrismeyersfsu/fix-4225

cancel job also cancels project update
This commit is contained in:
Chris Meyers 2016-12-15 08:46:43 -05:00 committed by GitHub
commit 7bc6d50b0b
2 changed files with 22 additions and 7 deletions

View File

@ -654,6 +654,15 @@ class Job(UnifiedJob, JobOptions, SurveyJobMixin, JobNotificationMixin):
def get_notification_friendly_name(self): def get_notification_friendly_name(self):
return "Job" return "Job"
'''
Canceling a job also cancels the implicit project update with launch_type
run.
'''
def cancel(self):
res = super(Job, self).cancel()
if self.project_update:
self.project_update.cancel()
return res
class JobHostSummary(CreatedModifiedModel): class JobHostSummary(CreatedModifiedModel):
''' '''

View File

@ -708,6 +708,11 @@ class BaseTask(Task):
stdout_handle.close() stdout_handle.close()
except Exception: except Exception:
pass pass
instance = self.update_model(pk)
if instance.cancel_flag:
status = 'canceled'
instance = self.update_model(pk, status=status, result_traceback=tb, instance = self.update_model(pk, status=status, result_traceback=tb,
output_replacements=output_replacements, output_replacements=output_replacements,
**extra_update_fields) **extra_update_fields)
@ -1045,17 +1050,18 @@ class RunJob(BaseTask):
local_project_sync = job.project.create_project_update(launch_type="sync") local_project_sync = job.project.create_project_update(launch_type="sync")
local_project_sync.job_type = 'run' local_project_sync.job_type = 'run'
local_project_sync.save() local_project_sync.save()
# save the associated project update before calling run() so that a
# cancel() call on the job can cancel the project update
job = self.update_model(job.pk, project_update=local_project_sync)
project_update_task = local_project_sync._get_task_class() project_update_task = local_project_sync._get_task_class()
try: try:
project_update_task().run(local_project_sync.id) project_update_task().run(local_project_sync.id)
job.scm_revision = job.project.scm_revision job = self.update_model(job.pk, scm_revision=project.scm_revision)
job.project_update = local_project_sync
job.save()
except Exception: except Exception:
job.status = 'failed' job = self.update_model(job.pk, status='failed',
job.job_explanation = 'Previous Task Failed: {"job_type": "%s", "job_name": "%s", "job_id": "%s"}' % \ job_explanation='Previous Task Failed: {"job_type": "%s", "job_name": "%s", "job_id": "%s"}' % \
('project_update', local_project_sync.name, local_project_sync.id) ('project_update', local_project_sync.name, local_project_sync.id))
job.save()
raise raise
def post_run_hook(self, job, status, **kwargs): def post_run_hook(self, job, status, **kwargs):