Форум сайта python.su
Всем привет, у меня возникла такая загвоздка:
Есть вебсокет сервер на socketIO:
import eventlet import socketio sio = socketio.Server(logger=True) app = socketio.WSGIApp(sio) @sio.event def connect(sid, environ): logger.info(f'Client with id: {sid} was connected') @sio.event def message(sid, data): # logger.debug(data) print(data) @sio.event def notification(sid, data): to, msg = list(data.items()).pop() print(to, msg) sio.send(msg, to=to) @sio.event def disconnect(sid): logger.info(f'Client with id: {sid} was disconnected ')
from celery import Celery sio = socketio.Client() celery: Celery = Celery('tasks', broker='redis://:156489@localhost/0', backend='redis://:156489@localhost/0') @sio.event def connect(): print('connection established') sio.emit('message', {'message': 'Task is connected'}) @sio.event def disconnect(): print('disconnected from server') @sio.event def message(data): print('message received with ', data) sio.connect('http://localhost:5000', headers={'token': 'task'}) @celery.on_after_configure.connect def setup_periodic_tasks(sender, **kwargs): sender.add_periodic_task(10.0, send_notifications.s(), name='add every 10') @celery.task(name='send_notifications') def send_notifications(): logger.info('Search new unread notifications') print(sio.connected) sio.emit('notification', {'key': 'val'}) sio.send('from task')
Отредактировано kadr1986 (Июнь 8, 2020 16:22:06)
Офлайн
Так connect у тебя обернута в декоратор @sio.event, а твой send_notifications только в @celery.task
Офлайн