Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specific message when canceling an already canceled job #15

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ingestclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import os
import time
import logging
import json


def get_confirmation(prompt, force=False):
Expand Down Expand Up @@ -186,6 +187,11 @@ def main(configuration=None, parser_args=None):
if not get_confirmation("Are you sure you want to cancel ingest job {}? ".format(args.job_id), args.force):
print("Command ignored. Job not cancelled")
sys.exit(0)

status = backend.get_job_status(args.job_id)
if status == 'deleted':
print(("Job {} already deleted").format(args.job_id))
sys.exit(0)

backend.cancel(args.job_id)
print("Ingest job {} successfully cancelled.".format(args.job_id))
Expand Down Expand Up @@ -228,6 +234,12 @@ def main(configuration=None, parser_args=None):
sys.exit(1)

if args.cancel:
# If cancelling with config_file
with open(args.config_file, 'r') as f:
config_dict = json.load(f)
backend = BossBackend(config_dict)
backend.setup(args.api_token)

# Trying to cancel
if args.job_id is None:
parser.print_usage()
Expand All @@ -238,6 +250,11 @@ def main(configuration=None, parser_args=None):
print("Command ignored. Job not cancelled")
sys.exit(0)

status = backend.get_job_status(args.job_id)
if status == 'deleted':
print(("Job {} already deleted").format(args.job_id))
sys.exit(0)

always_log_info("Attempting to cancel Ingest Job {}.".format(args.job_id))
engine.cancel()
always_log_info("Ingest job {} successfully cancelled.".format(args.job_id))
Expand Down
2 changes: 2 additions & 0 deletions ingestclient/core/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ def get_job_status(self, ingest_job_id):
r = requests.get('{}/{}/ingest/{}/status'.format(self.host, self.api_version, ingest_job_id),
headers=self.api_headers, verify=self.validate_ssl)

if r.text == '{"status": 404, "code": 2004, "message": "The job with id %s has been deleted"}' % (ingest_job_id):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should fix the response from the endpoint so it returns a normal 200 with the status set properly instead of a 404. Currently, we don't match our docs when getting status for a deleted job: https://theboss.readme.io/docs/get-ingest-job-status

Then in client.py, you can do a normal get_job_status() call.

Fix would be here: https://github.com/jhuapl-boss/boss/blob/08a0ddb86b7dedf1c0b029d9479db0dc2b11ff1a/django/bossingest/views.py#L362

return "deleted"
if r.status_code != 200:
raise Exception("Failed to get ingest job status: {}".format(r.text))
else:
Expand Down