search

Home  >  Q&A  >  body text

python - How to execute celery scheduled tasks without delay

When using celery to do scheduled tasks, such as the following code

app.conf.beat_schedule = {
    # 'login_task': {
    #     'task': 'tasks.login.excute_login_task',
    #     'schedule': 60*60*20.0,
    # },
    'test_celery': {
        'task': 'tasks.login.test_timertask',
        'schedule': 60.0,
    }
}

In use

celery beat -A tasks.login --loglevel=info

After

, there will be a delay of 60 seconds before executing the first task. I would like to ask, how can I write it so that it can be executed when the scheduled task is first started, and then executed again every 60 seconds?

伊谢尔伦伊谢尔伦2833 days ago936

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-05-18 11:00:11

    Simple method: call tasks.login.test_timertask() after or before this

    app.conf.beat_schedule = {

    # 'login_task': {
    #     'task': 'tasks.login.excute_login_task',
    #     'schedule': 60*60*20.0,
    # },
    'test_celery': {
        'task': 'tasks.login.test_timertask',
        'schedule': 60.0,
    }

    }

    reply
    0
  • Cancelreply