Я хочу настроить периодические задачи Celery, чтобы что-то делать с клиентом Paho MQTT. Рабочий показал, что он был успешно выполнен. Но в моем фиде сообщений Cloud MQTT Broker ничего не было.
### mqtt.py
import paho.mqtt.client as mqtt
#The callback for connecting to CloudMQTT broker
def on_connect(client, userdata, flags, rc):
print("Connecting to CloudMQTT broker: "+ mqtt.connack_string(rc))
# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, message):
print("Received message '" + str(message.payload) + "' on topic '"
+ message.topic + "' with QoS " + str(message.qos))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.username_pw_set('bmlflxes', 'Mj8LHanZvdkf')
client.connect('m11.cloudmqtt.com', 12180),
### tasks.py
from celery import Celery
from celery.schedules import crontab
from mqtt import client
app = Celery('tasks', backend='rpc://', broker='pyamqp://')
app.conf.beat_schedule = {
# Executes at sunset in Melbourne
'test': {
'task': 'tasks.hello',
'schedule': crontab(minute='*/1'),
'args': (),
},
}
@app.task
def add(x, y):
return x + y
@app.task
def hello():
client.publish('sys', 'hello')
### Worker log
[2018-09-13 21:44:00,048: INFO/MainProcess] Scheduler: Sending due task test (tasks.hello)
[2018-09-13 21:44:00,053: DEBUG/MainProcess] tasks.hello sent. id->7d88ae4b-821c-4485-87bc-454ac9bbac5e
[2018-09-13 21:44:00,054: DEBUG/MainProcess] beat: Waking up in 59.94 seconds.