Skip to content

Commit 4794dce

Browse files
committed
Fix build task done_callback to distinguish success/failure
_spawn_build_task now re-raises after reporting the event, so the done_callback can check t.exception() and log accurately instead of always logging 'completed'. No double event reporting since the build task runs as a detached asyncio.create_task outside the nri_error_handler scope.
1 parent 1c284e4 commit 4794dce

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

pkgs/nixkube/src/nri/server.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -379,16 +379,20 @@ async def CreateContainer(self, stream) -> None:
379379
nix_rw,
380380
)
381381
)
382-
# Log task completion
383-
task.add_done_callback(
384-
lambda t: (
385-
logger.info(
386-
f"Build task completed for container={container_id!r}"
382+
383+
def _build_done(t, cid=container_id):
384+
if t.cancelled():
385+
logger.warning(
386+
f"Build task cancelled for container={cid!r}"
387387
)
388-
if not t.cancelled()
389-
else None
390-
)
391-
)
388+
elif t.exception():
389+
logger.error(
390+
f"Build task failed for container={cid!r}: {t.exception()}"
391+
)
392+
else:
393+
logger.info(f"Build task completed for container={cid!r}")
394+
395+
task.add_done_callback(_build_done)
392396
else:
393397
logger.warning(
394398
f"Build already pending for container={container_id!r}"
@@ -585,6 +589,7 @@ async def _spawn_build_task(
585589
logs=str(e),
586590
event_type="Warning",
587591
)
592+
raise
588593
finally:
589594
# Cancel progress pump if it's still running
590595
if pump_task is not None:

0 commit comments

Comments
 (0)