I'm trying to create a chat that when it meets the condition of "hola" is sent by a task in celery. However, when it enters the condition the status is not updated, can someone help me?
I leave my code, please help!
Mi error is:
> [2018-04-18 01:11:25,798: WARNING/MainProcess] c:\python\lib\site-packages\celery\concurrency\base.py:31: RuntimeWarning: coroutine 'MensajeAlGrupo' was never awaited
ret = target(*args, **kwargs)
***consumers.py***
import json
from channels.generic.websocket import AsyncWebsocketConsumer
from .tasks import MensajeAlGrupo
class Consumidor(AsyncWebsocketConsumer):
async def connect(self):
# Join room group
await self.channel_layer.group_add(
'grupo',
self.channel_name
)
await self.accept()
async def disconnect(self, close_code):
await self.channel_layer.group_discard(
'grupo',
self.channel_name
)
# Receive message from WebSocket
async def receive(self, text_data):
text_data_json = json.loads(text_data)
message = text_data_json['message']
if str(message) == "hola":
MensajeAlGrupo.delay()
else:
# Send message to room group
await self.channel_layer.group_send(
'grupo',
{
'type': 'chat_message',
'message': message
}
)
# Receive message from room group
async def chat_message(self, event):
message = event['message']
# Send message to WebSocket
await self.send(text_data=json.dumps({
'message': message
}))
***Tasks.py***
#De celery
from Filtros.celery import app
from channels.layers import get_channel_layer
@app.task()
async def MensajeAlGrupo():
channel_layer = get_channel_layer()
await channel_layer.group_send(
'grupo',
{"type": "chat_message", "message": "Hello World"},
)
***celery.py***
#De celery
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Filtros.settings')
app = Celery('Proyecto')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
app.conf.update(
BROKER_URL = 'redis://127.0.0.1:6379/0',
)
Please help me, thx!
Sorry for my english :s
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b6eb8abf-86c2-4023-be4b-a2bd81d459e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment