Skip to content

Commit

Permalink
Merge 71e9221 into d5dc320
Browse files Browse the repository at this point in the history
  • Loading branch information
okraskaj committed Nov 14, 2018
2 parents d5dc320 + 71e9221 commit 3339fdb
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
27 changes: 27 additions & 0 deletions reana_client/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,30 @@ def upload_to_server(self, workflow, paths, access_token):
logging.debug(str(e))
logging.info("Something went wrong while uploading {}".
format(fname))

def stop_workflow(self, workflow, force_stop, access_token):
"""Stop a workflow."""
try:
parameters = {'force_stop': force_stop}
(response, http_response) = self._client.api.set_workflow_status(
workflow_id_or_name=workflow,
status='stopped',
access_token=access_token,
parameters=parameters).result()
if http_response.status_code == 200:
return response
else:
raise Exception(
"Expected status code 200 but replied with "
"{status_code}".format(
status_code=http_response.status_code))
except HTTPError as e:
logging.debug(
'Workflow run could not be stopped: '
'\nStatus: {}\nReason: {}\n'
'Message: {}'.format(e.response.status_code,
e.response.reason,
e.response.json()['message']))
raise Exception(e.response.json()['message'])
except Exception as e:
raise e
47 changes: 47 additions & 0 deletions reana_client/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,52 @@ def workflow_validate(ctx, file):
err=True)


@add_access_token_options
@click.pass_context
@click.command(
'stop',
help='Stop a running workflow')
@click.option(
'--force',
'force_stop',
is_flag=True,
default=False,
help='Stop a workflow without waiting for jobs to finish.')
@click.option(
'-w',
'--workflow',
default=os.environ.get('REANA_WORKON', None),
callback=workflow_uuid_or_name,
help='Name and run number to be stopped. '
'Overrides value of REANA_WORKON.')
def workflow_stop(ctx, workflow, force_stop, access_token):
"""Stop given workflow."""
if not force_stop:
click.secho('Graceful stop not implement yet. If you really want to '
'stop your workflow without waiting for jobs to finish'
' use: --force option', fg='red')
raise click.Abort()

if not access_token:
click.secho(
ERROR_MESSAGES['missing_access_token'], fg='red', err=True)
sys.exit(1)

if workflow:
try:
logging.info(
'Sending a request to stop workflow {}'.format(workflow))
response = ctx.obj.client.stop_workflow(workflow,
force_stop,
access_token)
click.secho('{} has been stopped.'.format(workflow), fg='green')
except Exception as e:
logging.debug(traceback.format_exc())
logging.debug(str(e))
click.secho('Workflow could not be stopped: \n{}'.format(str(e)),
fg='red', err=True)


@click.command(
'run',
help='Create, upload and start the REANA workflow.')
Expand Down Expand Up @@ -544,5 +590,6 @@ def workflow_run(ctx, file, filenames, name, skip_validation,
workflow.add_command(workflow_start)
workflow.add_command(workflow_validate)
workflow.add_command(workflow_status)
# workflow.add_command(workflow_stop)
workflow.add_command(workflow_run)
# workflow.add_command(workflow_logs)

0 comments on commit 3339fdb

Please sign in to comment.