mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 23:51:09 +03:00
Support cancel on system jobs
This commit is contained in:
parent
f945719794
commit
d011a87bb0
@ -1717,8 +1717,17 @@ class SystemJobSerializer(UnifiedJobSerializer):
|
||||
if obj.system_job_template and obj.system_job_template.active:
|
||||
res['system_job_template'] = reverse('api:system_job_template_detail',
|
||||
args=(obj.system_job_template.pk,))
|
||||
if obj.can_cancel or True:
|
||||
res['cancel'] = reverse('api:system_job_cancel', args=(obj.pk,))
|
||||
return res
|
||||
|
||||
class SystemJobCancelSerializer(SystemJobSerializer):
|
||||
|
||||
can_cancel = serializers.BooleanField(source='can_cancel', read_only=True)
|
||||
|
||||
class Meta:
|
||||
fields = ('can_cancel',)
|
||||
|
||||
class JobListSerializer(JobSerializer, UnifiedJobListSerializer):
|
||||
pass
|
||||
|
||||
|
@ -206,6 +206,7 @@ system_job_template_urls = patterns('awx.api.views',
|
||||
system_job_urls = patterns('awx.api.views',
|
||||
url(r'^$', 'system_job_list'),
|
||||
url(r'^(?P<pk>[0-9]+)/$', 'system_job_detail'),
|
||||
url(r'^(?P<pk>[0-9]+)/cancel/$', 'system_job_cancel'),
|
||||
)
|
||||
|
||||
schedule_urls = patterns('awx.api.views',
|
||||
|
@ -2745,6 +2745,21 @@ class SystemJobDetail(RetrieveDestroyAPIView):
|
||||
model = SystemJob
|
||||
serializer_class = SystemJobSerializer
|
||||
|
||||
class SystemJobCancel(RetrieveAPIView):
|
||||
|
||||
model = SystemJob
|
||||
serializer_class = SystemJobCancelSerializer
|
||||
is_job_cancel = True
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
if obj.can_cancel:
|
||||
obj.cancel()
|
||||
return Response(status=status.HTTP_202_ACCEPTED)
|
||||
else:
|
||||
return self.http_method_not_allowed(request, *args, **kwargs)
|
||||
|
||||
|
||||
class UnifiedJobTemplateList(ListAPIView):
|
||||
|
||||
model = UnifiedJobTemplate
|
||||
|
Loading…
Reference in New Issue
Block a user