mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 10:00:01 -03:30
Merge pull request #6790 from fherbert/feature/awx_cli_job_monitor
Add ability to monitor jobs and workflow_jobs via awx cli, fixes #6165 Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
commit
c2e9df74e4
@ -552,3 +552,41 @@ class SettingsModify(CustomAction):
|
||||
except json.decoder.JSONDecodeError:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
class HasMonitor(object):
|
||||
|
||||
action = 'monitor'
|
||||
|
||||
def add_arguments(self, parser, resource_options_parser):
|
||||
from .options import pk_or_name
|
||||
parser.choices[self.action].add_argument(
|
||||
'id',
|
||||
type=functools.partial(
|
||||
pk_or_name, None, self.resource, page=self.page
|
||||
),
|
||||
help=''
|
||||
)
|
||||
|
||||
def perform(self, **kwargs):
|
||||
response = self.page.get()
|
||||
mon = monitor_workflow if response.type == 'workflow_job' else monitor
|
||||
if not response.failed and response.status != 'successful':
|
||||
status = mon(
|
||||
response,
|
||||
self.page.connection.session,
|
||||
)
|
||||
if status:
|
||||
response.json['status'] = status
|
||||
if status in ('failed', 'error'):
|
||||
setattr(response, 'rc', 1)
|
||||
else:
|
||||
return 'Unable to monitor finished job'
|
||||
|
||||
|
||||
class JobMonitor(HasMonitor, CustomAction):
|
||||
resource = 'jobs'
|
||||
|
||||
|
||||
class WorkflowJobMonitor(HasMonitor, CustomAction):
|
||||
resource = 'workflow_jobs'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user