Skip to content
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
11 changes: 10 additions & 1 deletion src/sheppy/utils/task_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ async def execute_task(__task: "Task", worker_id: str) -> tuple[Exception | None
except Exception as e:
raise Exception("Middleware error") from e

return exception, task.create_task()
# result validation might fail
try:
final_task = task.create_task()
except Exception as e:
task = await TaskProcessor.handle_failed_task(task, e)
exception = e
final_task = task.create_task()

return exception, final_task

@staticmethod
async def process_pre_task_middleware(task: TaskInternal) -> tuple[TaskInternal, list[Any]]:
Expand Down Expand Up @@ -123,6 +131,7 @@ def handle_success_and_update_task_metadata(task: TaskInternal, result: Any, wor
@staticmethod
async def handle_failed_task(task: TaskInternal, exception: Exception) -> TaskInternal:
task.completed = False
task.result = None
task.error = f"{exception.__class__.__name__}: {exception}"

if task.is_retriable:
Expand Down
18 changes: 18 additions & 0 deletions tests/contract/test_edgecases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from sheppy import Queue, Worker, task
from sheppy.testqueue import assert_is_failed


@task
async def task_with_wrong_return_annotation() -> list:
return 5


async def test_wrong_return_annotation(queue: Queue, worker: Worker) -> None:
t = task_with_wrong_return_annotation()

await queue.add(t)
await worker.work(1)

t = await queue.get_task(t)

assert_is_failed(t)