Skip to content

Commit

Permalink
Merge pull request #6061 from mzimandl/sigusr1
Browse files Browse the repository at this point in the history
add sigusr1_handler again
  • Loading branch information
tomachalek authored Dec 15, 2023
2 parents a819d25 + dabd28d commit f22da7d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions public/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import logging
import os
import secrets
import signal
import sys
import tempfile
from datetime import datetime, timedelta, timezone
Expand Down Expand Up @@ -194,6 +195,7 @@ async def main_process_init(*_):
@application.listener('before_server_start')
async def server_init(app: Sanic, loop: asyncio.BaseEventLoop):
setproctitle(f'sanic-kontext [{CONF_PATH}][worker]')
loop.add_signal_handler(signal.SIGUSR1, lambda: asyncio.create_task(sigusr1_handler()))
# init extensions fabrics
app.ctx.client_session = aiohttp.ClientSession()
# runtime conf (this should have its own module in the future)
Expand Down Expand Up @@ -263,6 +265,7 @@ async def handle_soft_reset_signal():
fn = getattr(p.instance, 'on_soft_reset', None)
if callable(fn):
await fn()
await tt_cache.clear_all()
logging.getLogger(__name__).warning('performed internal soft reset (Sanic signal)')


Expand All @@ -277,6 +280,11 @@ async def soft_reset(req):
raise NotFound()


async def sigusr1_handler():
logging.getLogger(__name__).warning('Caught signal SIGUSR1')
await application.dispatch('kontext.internal.reset')


def get_locale(request: Request) -> str:
"""
Gets user locale based on request data
Expand Down

0 comments on commit f22da7d

Please sign in to comment.