Skip to content

Commit

Permalink
GTC-2939 Add job_link to OTF list response
Browse files Browse the repository at this point in the history
This gives the full URL for fetching the current job status.
  • Loading branch information
danscales committed Aug 13, 2024
1 parent 0fe58c1 commit 59b11f8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/pydantic/user_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class UserJob(BaseModel):
job_id: UUID
job_link: str = ""
status: str = "pending"
download_link: Optional[str] = None
failed_geometries_link: Optional[str] = None
Expand Down
6 changes: 6 additions & 0 deletions app/routes/jobs/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ...settings.globals import RASTER_ANALYSIS_STATE_MACHINE_ARN
from ...utils.aws import get_sfn_client
from ..datasets import _get_presigned_url_from_path
from app.settings.globals import API_URL

router = APIRouter()

Expand All @@ -41,6 +42,7 @@ async def get_job(*, job_id: UUID = Path(...)) -> UserJobResponse:

async def _get_user_job(job_id: UUID) -> UserJob:
execution = await _get_sfn_execution(job_id)
job_link = f"{API_URL}/job/{job_id}"

if execution["status"] == "SUCCEEDED":
output = (
Expand Down Expand Up @@ -68,6 +70,7 @@ async def _get_user_job(job_id: UUID) -> UserJob:
logger.error(f"Analysis service returned an unexpected response: {output}")
return UserJob(
job_id=job_id,
job_link=job_link,
status="failed",
download_link=None,
failed_geometries_link=None,
Expand All @@ -76,6 +79,7 @@ async def _get_user_job(job_id: UUID) -> UserJob:

return UserJob(
job_id=job_id,
job_link=job_link,
status=output["status"],
download_link=download_link,
failed_geometries_link=failed_geometries_link,
Expand All @@ -85,6 +89,7 @@ async def _get_user_job(job_id: UUID) -> UserJob:
elif execution["status"] == "RUNNING":
return UserJob(
job_id=job_id,
job_link=job_link,
status="pending",
download_link=None,
failed_geometries_link=None,
Expand All @@ -93,6 +98,7 @@ async def _get_user_job(job_id: UUID) -> UserJob:
else:
return UserJob(
job_id=job_id,
job_link=job_link,
status="failed",
download_link=None,
failed_geometries_link=None,
Expand Down
1 change: 1 addition & 0 deletions tests_v2/unit/app/routes/jobs/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ async def test_job_success(
data = resp.json()["data"]

assert data["job_id"] == TEST_JOB_ID
assert data["job_link"].endswith(f"/job/{TEST_JOB_ID}")
assert data["status"] == "success"
assert "test/results.csv" in data["download_link"]
assert data["failed_geometries_link"] is None
Expand Down

0 comments on commit 59b11f8

Please sign in to comment.