From 59b11f87f8c25cf26084fe903a06e2e334e92fa0 Mon Sep 17 00:00:00 2001 From: Dan Scales Date: Tue, 13 Aug 2024 11:18:20 -0700 Subject: [PATCH 1/2] GTC-2939 Add job_link to OTF list response This gives the full URL for fetching the current job status. --- app/models/pydantic/user_job.py | 1 + app/routes/jobs/job.py | 6 ++++++ tests_v2/unit/app/routes/jobs/test_job.py | 1 + 3 files changed, 8 insertions(+) diff --git a/app/models/pydantic/user_job.py b/app/models/pydantic/user_job.py index 4354ebbb..37ffbb1b 100644 --- a/app/models/pydantic/user_job.py +++ b/app/models/pydantic/user_job.py @@ -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 diff --git a/app/routes/jobs/job.py b/app/routes/jobs/job.py index 66dc9003..a64bcb30 100644 --- a/app/routes/jobs/job.py +++ b/app/routes/jobs/job.py @@ -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() @@ -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 = ( @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/tests_v2/unit/app/routes/jobs/test_job.py b/tests_v2/unit/app/routes/jobs/test_job.py index 4adab763..c4ffe7fe 100644 --- a/tests_v2/unit/app/routes/jobs/test_job.py +++ b/tests_v2/unit/app/routes/jobs/test_job.py @@ -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 From 120aa7c6a815f081e1dd61bcdf68943d558bedca Mon Sep 17 00:00:00 2001 From: Dan Scales Date: Tue, 13 Aug 2024 12:21:32 -0700 Subject: [PATCH 2/2] Fix to add job_link to OTF query response, not /job response --- app/models/pydantic/user_job.py | 2 +- app/routes/datasets/queries.py | 4 +++- app/routes/jobs/job.py | 6 ------ tests_v2/unit/app/routes/datasets/test_query.py | 1 + tests_v2/unit/app/routes/jobs/test_job.py | 1 - 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/models/pydantic/user_job.py b/app/models/pydantic/user_job.py index 37ffbb1b..69855732 100644 --- a/app/models/pydantic/user_job.py +++ b/app/models/pydantic/user_job.py @@ -8,7 +8,7 @@ class UserJob(BaseModel): job_id: UUID - job_link: str = "" + job_link: Optional[str] status: str = "pending" download_link: Optional[str] = None failed_geometries_link: Optional[str] = None diff --git a/app/routes/datasets/queries.py b/app/routes/datasets/queries.py index deddfff5..51ebdfe8 100755 --- a/app/routes/datasets/queries.py +++ b/app/routes/datasets/queries.py @@ -24,6 +24,7 @@ from pglast.parser import ParseError from pglast.printer import RawStream from pydantic.tools import parse_obj_as +from app.settings.globals import API_URL from ...application import db from ...authentication.api_keys import get_api_key @@ -419,7 +420,8 @@ async def query_dataset_list_post( logger.error(error) return HTTPException(500, "There was an error starting your job.") - return UserJobResponse(data=UserJob(job_id=job_id)) + job_link = f"{API_URL}/job/{job_id}" + return UserJobResponse(data=UserJob(job_id=job_id, job_link=job_link)) async def _start_batch_execution(job_id: UUID, input: Dict[str, Any]) -> None: diff --git a/app/routes/jobs/job.py b/app/routes/jobs/job.py index a64bcb30..66dc9003 100644 --- a/app/routes/jobs/job.py +++ b/app/routes/jobs/job.py @@ -17,7 +17,6 @@ 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() @@ -42,7 +41,6 @@ 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 = ( @@ -70,7 +68,6 @@ 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, @@ -79,7 +76,6 @@ 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, @@ -89,7 +85,6 @@ 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, @@ -98,7 +93,6 @@ 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, diff --git a/tests_v2/unit/app/routes/datasets/test_query.py b/tests_v2/unit/app/routes/datasets/test_query.py index 52fec368..254bc9b9 100755 --- a/tests_v2/unit/app/routes/datasets/test_query.py +++ b/tests_v2/unit/app/routes/datasets/test_query.py @@ -703,6 +703,7 @@ async def test_query_batch_feature_collection( assert False assert str(uuid) == data["job_id"] + assert data["job_link"].endswith(f"/job/{data['job_id']}") assert data["status"] == "pending" diff --git a/tests_v2/unit/app/routes/jobs/test_job.py b/tests_v2/unit/app/routes/jobs/test_job.py index c4ffe7fe..4adab763 100644 --- a/tests_v2/unit/app/routes/jobs/test_job.py +++ b/tests_v2/unit/app/routes/jobs/test_job.py @@ -145,7 +145,6 @@ 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