Skip to content

Commit

Permalink
add redys instance if available ;-)
Browse files Browse the repository at this point in the history
  • Loading branch information
manatlan committed Jun 9, 2024
1 parent 1e1c169 commit 59a7a36
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
5 changes: 4 additions & 1 deletion htagweb/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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):
Expand Down
45 changes: 45 additions & 0 deletions htagweb/serverredys.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 59a7a36

Please sign in to comment.