Skip to content

Commit 3c5b334

Browse files
Fix graceful shutdown of daemon jobs (#315)
1 parent 3505645 commit 3c5b334

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* context: Fixed reporting incorrect reindexing reason.
88
* exceptions: Fixed crash with `FrozenInstanceError` when exception is raised from callback.
9+
* jobs: Fixed graceful shutdown of daemon jobs.
910

1011
### Improved
1112

src/dipdup/scheduler.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import json
23
from datetime import datetime
34
from functools import partial
@@ -48,11 +49,13 @@ async def _job_wrapper(ctx: DipDupContext, *args, **kwargs) -> None:
4849
logger=logger,
4950
hook_config=hook_config,
5051
)
51-
52-
await job_ctx.fire_hook(hook_config.callback, *args, **kwargs)
53-
54-
if job_config.daemon:
55-
raise ConfigurationError('Daemon jobs are intended to run forever')
52+
try:
53+
await job_ctx.fire_hook(hook_config.callback, *args, **kwargs)
54+
except asyncio.CancelledError:
55+
pass
56+
else:
57+
if job_config.daemon:
58+
raise ConfigurationError('Daemon jobs are intended to run forever')
5659

5760
logger = FormattedLogger(
5861
name=f'dipdup.hooks.{hook_config.callback}',

0 commit comments

Comments
 (0)