From 4c5dbaefece0721e27b8d38a4e7daa043400b3cf Mon Sep 17 00:00:00 2001 From: timofey Date: Tue, 1 Nov 2022 07:26:00 +0000 Subject: [PATCH] maybe sigterm maybe handling --- v6d0auth/app.py | 5 ++--- v6d0auth/run_app.py | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/v6d0auth/app.py b/v6d0auth/app.py index 55c8b99..7c3dba5 100644 --- a/v6d0auth/app.py +++ b/v6d0auth/app.py @@ -7,12 +7,11 @@ from nacl.signing import VerifyKey from nacl.utils import random from v6d0auth import certs - -__all__ = ('V6D0AuthAppFactory',) - from v6d0auth.appfactory import AppFactory from v6d0auth.cdb import CDB, Role, AbstractRequest +__all__ = ('V6D0AuthAppFactory',) + class V6D0AuthAppFactory(AppFactory): def __init__(self, cdb: CDB): diff --git a/v6d0auth/run_app.py b/v6d0auth/run_app.py index 09265a8..0f6f4c4 100644 --- a/v6d0auth/run_app.py +++ b/v6d0auth/run_app.py @@ -1,4 +1,5 @@ import asyncio +import signal from aiohttp import web @@ -18,6 +19,13 @@ async def start_app(app: web.Application): "(Press CTRL+C to quit)".format(", ".join(names)) ) + loop = asyncio.get_running_loop() + + def sigtermed(*_args): + loop.create_task(app.shutdown()) + + signal.signal(signal.SIGTERM, sigtermed) + async def run_app(app: web.Application): await start_app(app)