i.krivosheev
i.krivosheev

Reputation: 397

Celerybeat execute task

I have celery task:

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

I add this task to celerybeat in the settings:

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

My projects structure:

enter image description here

Setting is in the settings.py, task define in application.py. How start periodic task?

I run celery beat -A application. Output:

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

Upvotes: 2

Views: 3600

Answers (1)

Martin Alderete
Martin Alderete

Reputation: 736

In order to process "scheduled" tasks you need to run "celery beat" as @user2097159 said.

celery -A <project> beat -l debug

To run workers for normal tasks (task you execute asynchronous) you need to launch a worker

celery -A <project> worker -l debug

-l meas log-level equals to debug, good for development. A good practice is to leave celery to set the tasks names instead of set name="something". When the worker run it will show a message with the registered tasks, be sure you tasks have been registered by celery. As soon as your tasks be sent to a worker or the beat you will see a log entry in its console.

Upvotes: 2

Related Questions