Celerybeat执行任务

时间:2015-07-29 14:33:33

标签: python 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.pyapplication.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

1 个答案:

答案 0 :(得分:2)

为了处理&#34;预定&#34;你需要运行的任务&#34;芹菜击败&#34; 正如@ user2097159所说。

celery -A <project> beat -l debug

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

celery -A <project> worker -l debug

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