zoukankan      html  css  js  c++  java
  • 平台项目~celery基础独立

       0 编辑py文件celery_task.py
       1 from celery import Celery 引入模块 4.0
       2 ap =Celery('tasks',broker=CELERY_BROKER,backend=CELERY_BACKEND)
         broker 消费队列 可使用redis/rabbitmq方式存储消费队列
         backend任务结果队列 可使用redis/rabbitmq方式存储消费队列
        rabbitMQ:大而全,更安全,数据处理更快速。redis:使用更方便,开发更快速
      3 @app.task(参数) # @app.task 指定将这个函数的执行交给celery异步执行
      补充
      1 autoretry_for=(Exception,) 当出现异常的时候自动进行尝试 Exception所有异常都需要重试
      2 retry_kwargs={'max_retries':Constant.MAX_RETRY,'countdown':Constant.RETRY_INTERVAL}
        当出现问题的时候规定的最大尝试次数和每次尝试的间隔时间 def add(x, y): return x + y
    4 启动/停止
       celery worker -A celery_task.py --concurrency=N --loglevel=info(开启N个并行线程)
       ps aux|grep "celery worker"|grep -v grep|awk '{print $2}'|xargs kill -9
    5 进行调用加入celery中
      method.delay()
    6 常用命令
      1 celery -A task_entry inspect active 查看正在运行的所有任务
      2 celery -A task_entry inspect reserved   等待调度等
      3 celery -A task_entry inspect registered 注册成功的任务可以进行验证是否生效

  • 相关阅读:
    AJAX封装(IE)
    CSS3线性渐变
    [Kafka] [All about it]
    [Java][内存模型]
    [python] [Jupyter Notebook]
    [Paper][Link note]
    [TODO]
    [Java] [Singleton] [DCL][happens-before]
    [Java concurrent][Collections]
    Unity AssetBundles and Resources指引 (四) AssetBundle使用模式
  • 原文地址:https://www.cnblogs.com/danhuangpai/p/13995730.html
Copyright © 2011-2022 走看看