newmediamonitoring1/polls/tasks.py

20 lines
612 B
Python
Raw Normal View History

2020-09-20 11:14:54 +00:00
from background_task import background
from channels.layers import get_channel_layer
from asgiref.sync import async_to_sync
from polls.models import Message
@background(schedule=1)
def process_task(task, groups, user_id):
print(groups)
for g in groups:
print(g)
# async_to_sync(channel_layer.group_send)(g['id'], {
# "type": 0,
# "send_from": user_id,
# "group_id": g['id'],
# "content": task['content']
# })
channel_layer = get_channel_layer()
async_to_sync(channel_layer.send)('test_channel', {'type': g['id']})