Skip to content

Commit

Permalink
Support cancel on system jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
matburt committed Jun 11, 2015
1 parent f945719 commit d011a87
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions awx/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1717,8 +1717,17 @@ def get_related(self, obj):
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

Expand Down
1 change: 1 addition & 0 deletions awx/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def url(regex, view, kwargs=None, name=None, prefix=''):
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',
Expand Down
15 changes: 15 additions & 0 deletions awx/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d011a87

Please sign in to comment.