style(v2): normalize worker lifecycle imports
This commit is contained in:
@@ -7,9 +7,9 @@ import asyncio
|
||||
from collections.abc import Callable, Sequence
|
||||
from pathlib import Path
|
||||
|
||||
from alembic import command
|
||||
from alembic.config import Config
|
||||
|
||||
from alembic import command
|
||||
from backup_tool import __version__
|
||||
from backup_tool.config import Settings
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ The worker owns leases; backup publishing is deliberately supplied by later M6 w
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import contextlib
|
||||
import signal
|
||||
from datetime import UTC, datetime
|
||||
from uuid import uuid4
|
||||
@@ -67,10 +68,8 @@ class Worker:
|
||||
await self.startup()
|
||||
while not self._stopping.is_set():
|
||||
if not await self.run_once():
|
||||
try:
|
||||
with contextlib.suppress(TimeoutError):
|
||||
await asyncio.wait_for(self._stopping.wait(), timeout=0.25)
|
||||
except TimeoutError:
|
||||
pass
|
||||
await self.engine.dispose()
|
||||
|
||||
def stop(self) -> None:
|
||||
@@ -81,10 +80,8 @@ def run_worker(settings: Settings) -> int:
|
||||
worker = Worker(settings)
|
||||
loop = asyncio.new_event_loop()
|
||||
for sig in (signal.SIGINT, signal.SIGTERM):
|
||||
try:
|
||||
with contextlib.suppress(NotImplementedError):
|
||||
loop.add_signal_handler(sig, worker.stop)
|
||||
except NotImplementedError:
|
||||
pass
|
||||
try:
|
||||
loop.run_until_complete(worker.run())
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user