Skip to content

Commit 8ddc980

Browse files
Graceful shutdown fixes (#218)
1 parent eac15e6 commit 8ddc980

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
Please use [this](https://docs.gitlab.com/ee/development/changelog.html) document as guidelines to keep a changelog.
44

5+
## [unreleased]
6+
7+
### Fixed
8+
9+
* cli: Ignore `SIGINT` signal when shutdown is in progress.
10+
* sentry: Ignore exceptions when shutdown is in progress.
11+
512
## 4.1.1 - 2022-01-25
613

714
### Fixed

src/dipdup/cli.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from dipdup.utils.database import wipe_schema
5858

5959
_logger = logging.getLogger('dipdup.cli')
60+
_is_shutting_down = False
6061

6162

6263
def echo(message: str) -> None:
@@ -72,6 +73,11 @@ class CLIContext:
7273

7374

7475
async def shutdown() -> None:
76+
global _is_shutting_down
77+
if _is_shutting_down:
78+
return
79+
_is_shutting_down = True
80+
7581
_logger.info('Shutting down')
7682
tasks = filter(lambda t: t != asyncio.current_task(), asyncio.all_tasks())
7783
list(map(asyncio.Task.cancel, tasks))
@@ -95,6 +101,12 @@ async def wrapper(*args, **kwargs) -> None:
95101
return wrapper
96102

97103

104+
def _sentry_before_send(event, _):
105+
if _is_shutting_down:
106+
return None
107+
return event
108+
109+
98110
def init_sentry(config: DipDupConfig) -> None:
99111
if not config.sentry:
100112
return
@@ -116,6 +128,7 @@ def init_sentry(config: DipDupConfig) -> None:
116128
integrations=integrations,
117129
release=__version__,
118130
attach_stacktrace=attach_stacktrace,
131+
before_send=_sentry_before_send,
119132
)
120133

121134

src/dipdup/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async def __aenter__(self) -> None:
8080

8181
async def __aexit__(self, exc_type, exc, tb):
8282
"""Close underlying aiohttp session"""
83-
self._logger.info('Closing gateway session (%s)', self._url)
83+
self._logger.debug('Closing gateway session (%s)', self._url)
8484
await self.__session.close()
8585

8686
@property

0 commit comments

Comments
 (0)