【发布时间】:2020-04-30 22:45:04
【问题描述】:
我有一个 Celery worker 配置为连接到 redis,如下所示:
celery_app_site24x7 = Celery('monitoringExterne.celerys.site24x7',
broker=settings.REDIS['broker'], backend=settings.REDIS['backend'])
celery_app_site24x7.conf.broker_transport_options = {
'visibility_timeout': 36000
}
celery_app_site24x7.conf.socket_timeout = 300
celery_app_site24x7.conf.broker_connection_max_retries = None
celery_app_site24x7.config_from_object('django.conf:settings')
celery_app_site24x7.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
问题是,如果 Redis 关闭并重新建立连接,则不会执行添加到队列中的新任务:
[2020-01-13 10:10:14,517: ERROR/MainProcess] consumer: Cannot connect to redis://xxx.xxx.xxx.xx:6380/10: Error while reading from socket: ('Connection closed by server.',).
Trying again in 2.00 seconds...
[2020-01-13 10:10:16,590: INFO/MainProcess] Connected to redis://xxx.xxx.xxx.xx:6380/10
[2020-01-13 10:10:16,699: INFO/MainProcess] mingle: searching for neighbors
[2020-01-13 10:10:17,766: INFO/MainProcess] mingle: all alone
我已经通过 django shell 手动调用了一个 celery 任务,如下所示:
celery_tasks.site24x7.test.delay()
它返回异步任务 ID,但工作人员不处理此任务。
<AsyncResult:ff634b85-edb5-44d4-bdb1-17a220761fcc>
如果我继续延迟启动任务,队列会不断增加:
127.0.0.1:6379[10]> llen site24x7
(integer) 4
127.0.0.1:6379[10]> llen site24x7
(integer) 5
下面是芹菜状态和检查的输出
$ celery -A monitoringExterne --app=monitoringExterne.celerys.site24x7
状态错误:在时间限制内没有节点回复。
$ celery -A monitoringExterne --app=monitoringExterne.celerys.site24x7 检查活动
错误:在时间限制内没有节点回复。
【问题讨论】:
标签: python python-3.x redis celery