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

fix(saq-controller): Return a 404 status code when the job is not found #5

Merged
merged 1 commit into from
Oct 5, 2023
Merged
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
3 changes: 3 additions & 0 deletions litestar_saq/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from litestar import Controller, MediaType, get, post
from litestar.exceptions import NotFoundException
from litestar.status_codes import HTTP_202_ACCEPTED

from litestar_saq import info, urls

Expand Down Expand Up @@ -77,6 +78,7 @@ async def job_detail(self, task_queues: dict[str, Queue], queue_id: str, job_id:
cache=False,
summary="Job Retry",
description="Retry a failed job..",
status_code=HTTP_202_ACCEPTED,
)
async def job_retry(self, task_queues: dict[str, Queue], queue_id: str, job_id: str) -> dict:
"""Retry job."""
Expand All @@ -96,6 +98,7 @@ async def job_retry(self, task_queues: dict[str, Queue], queue_id: str, job_id:
cache=False,
summary="Job Abort",
description="Abort active job.",
status_code=HTTP_202_ACCEPTED,
)
async def job_abort(self, task_queues: dict[str, Queue], queue_id: str, job_id: str) -> dict:
"""Abort job."""
Expand Down
6 changes: 3 additions & 3 deletions litestar_saq/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import TYPE_CHECKING, cast

from .exceptions import LitestarSaqError
from litestar.exceptions import NotFoundException

if TYPE_CHECKING:
from .base import Job, Queue
Expand All @@ -11,6 +11,6 @@
async def job(queue: Queue, job_id: str) -> Job:
job = await queue._get_job_by_id(job_id) # noqa: SLF001
if not job:
msg = "Could not find job ID %s"
raise LitestarSaqError(msg, job_id)
msg = f"Could not find job ID {job_id}"
raise NotFoundException(msg)
cofin marked this conversation as resolved.
Show resolved Hide resolved
return cast("Job", job)