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