diff --git a/htagweb/runners.py b/htagweb/runners.py index 85cf163..c4f8b66 100644 --- a/htagweb/runners.py +++ b/htagweb/runners.py @@ -34,10 +34,11 @@ from htag.runners import commons #/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ -from . import crypto +from . import crypto,serverredys from .session import Session from .fqn import findfqn from .hrclient import HrClient + #/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ logger = logging.getLogger(__name__) @@ -183,10 +184,12 @@ async def on_disconnect(self, websocket, close_code): @contextlib.asynccontextmanager async def lifespan(app): print("--- START") + await serverredys.start() await HrClient.clean() yield print("--- STOP") await HrClient.clean() + serverredys.stop() class Runner(Starlette): diff --git a/htagweb/serverredys.py b/htagweb/serverredys.py new file mode 100644 index 0000000..a1cc408 --- /dev/null +++ b/htagweb/serverredys.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# ############################################################################# +# Copyright (C) 2024 manatlan manatlan[at]gmail(dot)com +# +# MIT licence +# +# https://github.com/manatlan/htagweb +# ############################################################################# +import asyncio +try: + import redys.v2 + + _S = None + + ################################################################################## + async def start(): + ################################################################################## + global _S + # start a redys server (only one will win) + _S=redys.v2.ServerProcess() + + # wait redys up + bus=redys.v2.AClient() + while 1: + try: + if await bus.ping()=="pong": + break + except: + pass + await asyncio.sleep(0.1) + + + ################################################################################## + def stop(): + ################################################################################## + global _S + if _S: + _S.stop() + +except ImportError: + print("redys server not supported") + async def start(): + pass + def stop(s): + pass diff --git a/pyproject.toml b/pyproject.toml index 2d095be..fbcb3c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ pytest-cov = "^4.1.0" httpx = "0.24.0" gunicorn = "^22.0.0" beautifulsoup4 = "^4.12.3" +redys = "^0.9.20" [build-system] requires = ["poetry-core"]