• celery制作定时任务


    celery参考地址:http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html#starting-the-scheduler

    安装依赖文件:

     # 生成命令 pip freeze >> requirement.txt

    # 安装命令 pip install -r requirement.txt

    DateTime==4.3
    amqp==2.4.2
    billiard==3.6.0.0
    celery==4.3.0
    kombu==4.5.0
    pytz==2019.1
    redis==3.2.1
    tzlocal==1.5.1
    vine==1.3.0
    zope.interface==4.6.0

    源文件:

    # celery_task.py

    from celery import Celery
    from celery.schedules import crontab
    from tzlocal import get_localzone


    app = Celery('crontab_task', broker='redis://localhost:6379/0')

    app.conf.timezone = get_localzone() # 获得本地时区,比pytz要好用

    @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 -A celery_task beat  

    下面为成功显示信息
    celery beat v4.3.0 (rhubarb) is starting.
    __ - ... __ - _
    LocalTime -> 2019-04-11 15:27:17
    Configuration ->
    . broker -> redis://localhost:6379/0
    . loader -> celery.loaders.app.AppLoader
    . scheduler -> celery.beat.PersistentScheduler
    . db -> celerybeat-schedule
    . logfile -> [stderr]@%WARNING
    . maxinterval -> 5.00 minutes (300s)

    执行任务:

    celery -A celery_task worker --loglevel=info

  • 相关阅读:
    arm架构与体系结构
    C语言双链表遍历,插入,删除
    C语言实现单链表的遍历,逆序,插入,删除
    C语言函数的变参实用与分析
    DEBUG宏
    运算中的临时匿名变量
    main函数的传参与返回
    存储类、作用域、生命周期、链接属性
    制作动态链接库并使用
    内存管理——进程创建,执行,缺页,终止
  • 原文地址:https://www.cnblogs.com/zxpo/p/10690093.html
Copyright © 2020-2023  润新知