Skip to content

Commit

Permalink
Implement an option to choose a job type on relaunch (issue #14177)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sasa Jovicic authored and Sasa993 committed Jan 14, 2025
1 parent f89be5e commit 2b98fcd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion awx/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3352,11 +3352,17 @@ class JobRelaunchSerializer(BaseSerializer):
choices=[('all', _('No change to job limit')), ('failed', _('All failed and unreachable hosts'))],
write_only=True,
)
job_type = serializers.ChoiceField(
required=False,
allow_null=True,
choices=NEW_JOB_TYPE_CHOICES,
write_only=True,
)
credential_passwords = VerbatimField(required=True, write_only=True)

class Meta:
model = Job
fields = ('passwords_needed_to_start', 'retry_counts', 'hosts', 'credential_passwords')
fields = ('passwords_needed_to_start', 'retry_counts', 'hosts', 'job_type', 'credential_passwords')

def validate_credential_passwords(self, value):
pnts = self.instance.passwords_needed_to_start
Expand Down
3 changes: 3 additions & 0 deletions awx/api/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3435,6 +3435,7 @@ def post(self, request, *args, **kwargs):

copy_kwargs = {}
retry_hosts = serializer.validated_data.get('hosts', None)
job_type = serializer.validated_data.get('job_type', None)
if retry_hosts and retry_hosts != 'all':
if obj.status in ACTIVE_STATES:
return Response(
Expand All @@ -3455,6 +3456,8 @@ def post(self, request, *args, **kwargs):
)
copy_kwargs['limit'] = ','.join(retry_host_list)

if job_type:
copy_kwargs['job_type'] = job_type
new_job = obj.copy_unified_job(**copy_kwargs)
result = new_job.signal_start(**serializer.validated_data['credential_passwords'])
if not result:
Expand Down

0 comments on commit 2b98fcd

Please sign in to comment.