mirror of
https://github.com/ansible/awx.git
synced 2026-03-17 17:07:33 -02:30
Fix wsbroadcast for django 3.0+ async
From https://docs.djangoproject.com/en/3.0/topics/async/#asgiref.sync.sync_to_async
This commit is contained in:
committed by
Jeff Bradberry
parent
df61d1a59c
commit
efff85bc1f
@@ -4,6 +4,7 @@ import asyncio
|
|||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from aiohttp import client_exceptions
|
from aiohttp import client_exceptions
|
||||||
|
from asgiref.sync import sync_to_async
|
||||||
|
|
||||||
from channels.layers import get_channel_layer
|
from channels.layers import get_channel_layer
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ def unwrap_broadcast_msg(payload: dict):
|
|||||||
return (payload['group'], payload['message'])
|
return (payload['group'], payload['message'])
|
||||||
|
|
||||||
|
|
||||||
|
@sync_to_async
|
||||||
def get_broadcast_hosts():
|
def get_broadcast_hosts():
|
||||||
Instance = apps.get_model('main', 'Instance')
|
Instance = apps.get_model('main', 'Instance')
|
||||||
instances = (
|
instances = (
|
||||||
@@ -170,7 +172,7 @@ class BroadcastWebsocketManager(object):
|
|||||||
async def run_per_host_websocket(self):
|
async def run_per_host_websocket(self):
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
known_hosts = get_broadcast_hosts()
|
known_hosts = await get_broadcast_hosts()
|
||||||
future_remote_hosts = known_hosts.keys()
|
future_remote_hosts = known_hosts.keys()
|
||||||
current_remote_hosts = self.broadcast_tasks.keys()
|
current_remote_hosts = self.broadcast_tasks.keys()
|
||||||
deleted_remote_hosts = set(current_remote_hosts) - set(future_remote_hosts)
|
deleted_remote_hosts = set(current_remote_hosts) - set(future_remote_hosts)
|
||||||
|
|||||||
Reference in New Issue
Block a user