gpt4 book ai didi

python - Celerybeat 执行任务

转载 作者:太空宇宙 更新时间:2023-11-04 03:29:18 24 4
gpt4 key购买 nike

我有 celery 任务:

@app.task(ignore_result=True)
def update_task():
....

我在设置中将此任务添加到 celerybeat:

CELERYBEAT_SCHEDULE = {
"update-task-on-mathmod.org": {
"task": "manager.update_task",
"schedule": timedelta(seconds=30),
}
}

我的项目结构:

enter image description here

设置在settings.py中,任务定义在application.py中。如何启动周期性任务?

我运行 celery beat -A application。输出:

celery beat v3.1.18 (Cipater) is starting.
__ - ... __ - _
Configuration ->
. broker -> amqp://guest:**@localhost:5672//
. loader -> celery.loaders.app.AppLoader
. scheduler -> celery.beat.PersistentScheduler
. db -> celerybeat-schedule
. logfile -> [stderr]@%DEBUG
. maxinterval -> now (0s)
[2015-07-30 11:27:16,470: DEBUG/MainProcess] Setting default socket timeout to 30
[2015-07-30 11:27:16,470: INFO/MainProcess] beat: Starting...
[2015-07-30 11:27:16,482: DEBUG/MainProcess] Current schedule:
<Entry: celery.backend_cleanup celery.backend_cleanup() <crontab: 0 4 * * * (m/h/d/dM/MY)>
[2015-07-30 11:27:16,483: DEBUG/MainProcess] beat: Ticking with max interval->5.00 minutes
[2015-07-30 11:27:16,495: DEBUG/MainProcess] Start from server, version: 0.9, properties: {u'information': u'Licensed under the MPL. See http://www.rabbitmq.com/', u'product': u'RabbitMQ', u'copyright': u'Copyright (C) 2007-2013 GoPivotal, Inc.', u'capabilities': {u'exchange_exchange_bindings': True, u'connection.blocked': True, u'authentication_failure_close': True, u'basic.nack': True, u'consumer_priorities': True, u'consumer_cancel_notify': True, u'publisher_confirms': True}, u'platform': u'Erlang/OTP', u'version': u'3.2.4'}, mechanisms: [u'AMQPLAIN', u'PLAIN'], locales: [u'en_US']
[2015-07-30 11:27:16,497: DEBUG/MainProcess] Open OK!
[2015-07-30 11:27:16,498: DEBUG/MainProcess] beat: Waking up in 5.00 minutes

最佳答案

为了处理“预定”任务,您需要运行“celery beat”正如@user2097159 所说。

celery -A <project> beat -l debug

要为正常任务运行工作人员(异步执行的任务),您需要启动工作人员

celery -A <project> worker -l debug

-l meas log-level 等于debug,有利于开发。一个好的做法是让 celery 来设置任务名称而不是 set name="something"。当工作人员运行时,它会显示一条包含已注册任务的消息,请确保您的任务已由 celery 注册。一旦您的任务被发送给工作人员或节拍,您就会在其控制台中看到一个日志条目。

关于python - Celerybeat 执行任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31703541/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com