Merge pull request #4320 from chrismeyersfsu/fix-ws_group_timeout

cleanup channel groups on start
This commit is contained in:
Chris Meyers
2020-05-11 15:52:04 -04:00
committed by GitHub
2 changed files with 25 additions and 1 deletions

View File

@@ -1,14 +1,37 @@
import redis
import logging
from django.conf.urls import url from django.conf.urls import url
from django.conf import settings
from channels.auth import AuthMiddlewareStack from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter from channels.routing import ProtocolTypeRouter, URLRouter
from . import consumers from . import consumers
logger = logging.getLogger('awx.main.routing')
class AWXProtocolTypeRouter(ProtocolTypeRouter):
def __init__(self, *args, **kwargs):
try:
r = redis.Redis.from_url(settings.BROKER_URL)
for k in r.scan_iter('asgi:*', 500):
logger.debug(f"cleaning up Redis key {k}")
r.delete(k)
except redis.exceptions.RedisError as e:
logger.warn("encountered an error communicating with redis.")
raise e
super().__init__(*args, **kwargs)
websocket_urlpatterns = [ websocket_urlpatterns = [
url(r'websocket/$', consumers.EventConsumer), url(r'websocket/$', consumers.EventConsumer),
url(r'websocket/broadcast/$', consumers.BroadcastConsumer), url(r'websocket/broadcast/$', consumers.BroadcastConsumer),
] ]
application = ProtocolTypeRouter({ application = AWXProtocolTypeRouter({
'websocket': AuthMiddlewareStack( 'websocket': AuthMiddlewareStack(
URLRouter(websocket_urlpatterns) URLRouter(websocket_urlpatterns)
), ),

View File

@@ -957,6 +957,7 @@ CHANNEL_LAYERS = {
"CONFIG": { "CONFIG": {
"hosts": [BROKER_URL], "hosts": [BROKER_URL],
"capacity": 10000, "capacity": 10000,
"group_expiry": 157784760, # 5 years
}, },
}, },
} }