Skip to content

Commit

Permalink
Fix to add job_link to OTF query response, not /job response
Browse files Browse the repository at this point in the history
  • Loading branch information
danscales committed Aug 13, 2024
1 parent 59b11f8 commit 120aa7c
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/models/pydantic/user_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion app/routes/datasets/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions app/routes/jobs/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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 = (
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tests_v2/unit/app/routes/datasets/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 0 additions & 1 deletion tests_v2/unit/app/routes/jobs/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 120aa7c

Please sign in to comment.