task handler returns task and subtask IDs

This commit is contained in:
Daniel Roth 2026-06-23 10:33:38 +00:00
parent 95d6ee1a33
commit 0a3b827be2

View file

@ -42,7 +42,7 @@ def task_handler(
@wraps(func)
def wrapper(event: dict[str, Any], context: Any) -> Any:
with factory() as orchestrator:
results: list[Any] = []
task_ids: list[dict[str, str]] = []
failures: list[dict[str, Any]] = []
for record in _records(event):
@ -52,19 +52,21 @@ def task_handler(
str(raw_source_id) if raw_source_id is not None else None
)
_, subtask = orchestrator.create_task_with_subtask(
task, subtask = orchestrator.create_task_with_subtask(
task_source=task_source,
inputs=body,
source=source,
source_id=source_id,
)
task_ids.append(
{"task_id": str(task.id), "subtask_id": str(subtask.id)}
)
try:
result = orchestrator.run_subtask(
orchestrator.run_subtask(
subtask.id,
work=lambda body=body: func(body, context),
)
results.append(result)
except Exception:
logger.exception(
"subtask failed (task_source=%s source_id=%s)",
@ -78,8 +80,8 @@ def task_handler(
raise
if "Records" in event:
return {"batchItemFailures": failures}
return results
return {"batchItemFailures": failures, "tasks": task_ids}
return task_ids
return wrapper