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

Add job_urls field to post_jobs response #1616

Closed
wants to merge 6 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
10 changes: 10 additions & 0 deletions apps/api/src/hyp3_api/api-spec/openapi-spec.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,14 @@ components:
description: List of submitted jobs.
type: object
required:
- job_urls
- jobs
additionalProperties: false
properties:
validate_only:
$ref: "#/components/schemas/validate_only"
job_urls:
$ref: "#/components/schemas/job_urls"
jobs:
$ref: "#/components/schemas/list_of_jobs"
next:
Expand Down Expand Up @@ -443,6 +446,13 @@ components:
type: boolean
default: false

job_urls:
type: array
items:
type: string
format: url
example: https://hyp3-api.asf.alaska.edu/jobs/27836b79-e5b2-4d8f-932f-659724ea02c3

job_or_subscription_id:
description: Unique identifier for a job or subscription
type: string
Expand Down
10 changes: 10 additions & 0 deletions apps/api/src/hyp3_api/handlers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import urllib.parse
from http.client import responses
from uuid import UUID

Expand Down Expand Up @@ -31,6 +32,12 @@ def is_uuid(val):
return True


def base_url() -> str:
parts = urllib.parse.urlparse(request.base_url)
return urllib.parse.urlunparse((parts.scheme, parts.netloc, '', '', '', ''))


# TODO add or update unit test(s)
def post_jobs(body, user):
print(body)

Expand All @@ -46,9 +53,12 @@ def post_jobs(body, user):
body['jobs'] = dynamo.jobs.put_jobs(user, body['jobs'])
except dynamo.jobs.QuotaError as e:
abort(problem_format(400, str(e)))
base = base_url()
body['job_urls'] = [f'{base}/jobs/{job["job_id"]}' for job in body['jobs']]
return body


# TODO add job_urls field
def get_jobs(user, start=None, end=None, status_code=None, name=None, job_type=None, start_token=None,
subscription_id=None):
try:
Expand Down