码迷,mamicode.com
首页 > 其他好文 > 详细

Celery Beat定时任务

时间:2020-02-15 23:37:14      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:after   broker   ever   setup   div   exp   call   tab   from   

示例代码

创建schedule_tasks.py文件

from celery import Celery
from celery.schedules import crontab

app = Celery("SchedulerTasks", broker=pyamqp://admin:admin@172.16.37.200:5672//)


@app.on_after_configure.connect
def setup_periodic_tasks(sender, **kwargs):
    # Calls test(‘hello‘) every 10 seconds.
    sender.add_periodic_task(10.0, test.s(hello), name=add every 10)

    # Calls test(‘world‘) every 30 seconds
    sender.add_periodic_task(30.0, test.s(world), expires=10)

    # Executes every Monday morning at 7:30 a.m.
    sender.add_periodic_task(
        crontab(hour=7, minute=30, day_of_week=1),
        test.s(Happy Mondays!),
    )


@app.task
def test(arg):
    print(arg)

 

启动Celery Beat-任务生产者

# celery -A schedule_tasks beat

 

启动Celery Worker-任务消费者

# celery -A schedule_tasks worker 

 

Celery Beat定时任务

标签:after   broker   ever   setup   div   exp   call   tab   from   

原文地址:https://www.cnblogs.com/vincenshen/p/12315132.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!