Skip to content

Commit 4f89774

Browse files
committed
fix(Runner): raise if exception during user startup task
1 parent e4cd06c commit 4f89774

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

silverback/runner.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ async def run_system_task(
9090
return_type: Type | None = system_task_kicker.__annotations__.get("return")
9191
return TypeAdapter(return_type).validate_python(result.return_value)
9292

93-
async def run_task(self, task_data: TaskData, *args):
93+
async def run_task(self, task_data: TaskData, *args, raise_on_error: bool = False):
9494
task = await self.get_task(task_data.name).kiq(*args)
9595
task_result = await task.wait_result()
96-
task_error = task_result.error
96+
if (task_error := task_result.error) and raise_on_error:
97+
raise task_error
98+
9799
result = TaskResult.from_taskiq(task_data.name, task_result)
98100

99101
if metrics_str := "\n ".join(
@@ -228,7 +230,10 @@ async def startup(self) -> list[Coroutine]:
228230
TaskType.SYSTEM_USER_TASKDATA, TaskType.STARTUP
229231
):
230232
exceptions_or_none = await quattro.gather(
231-
*map(lambda td: self.run_task(td, startup_state), startup_tasks_taskdata),
233+
*map(
234+
lambda td: self.run_task(td, startup_state, raise_on_error=True),
235+
startup_tasks_taskdata,
236+
),
232237
# NOTE: Any propagated failure in here should be handled so shutdown tasks run
233238
return_exceptions=True,
234239
)

0 commit comments

Comments
 (0)