python学习笔记3-celery分布式任务处理器
import sys
reload(sys)
sys.setdefaultencoding('utf-8’) # 不加这句话,打印中文log会出错 from celery import Celery celery = Celery('tasks', broker='redis://127.0.0.1:6379/0') #选择本地redis db=0 作为消息载体, 第一个参数为任务名称
from celery.utils.log import get_task_logger # 倒入celery 中的log模块
logger = get_task_logger(__name__) @celery.task(bind=True, max_retries=10,
default_retry_delay=1 * 6) # bind 表示开启, max_retries 是重新尝试的次数,default_retry_delay 是默认的间隔时间,尝试的时间
def exec_task_order_overtime(self, order_id): # 订单到期后,执行订单失效的任务
try:
logger.info('===================> exec_task_order_overtime order_id=%s' % order_id)
success = BaseHandler.context_services.order_overtime_task_service.process_over_time(order_id)
if success is False:
logger.error(
'<================order_overtime_task_service.process_over_time Failed, order_id=%s' % order_id)
raise Return(False)
else:
logger.info(
'<=================order_overtime_task_service.process_over_time Success, order_id=%s' % order_id)
except Exception as exc:
logger.info('exec_task_order_overtime retry, order_id=%s' % order_id)
raise self.retry(exc=exc, countdown=3) # 3 秒后继续尝试, 此处的countdown 优先级高于装饰器中的default_retry_delay
from celery import Celery
celery = Celery('tasks', broker='redis://127.0.0.1:6379/0') #消息载体
push_task_id = celery.send_task('tasks.exec_task_order_overtime'
, [order_id] # 参数,必须为list,具体可见源码,第三个可以为dict,我们这里没有使用
, countdown=10) #延时多久执行 推送消息
疑问1:
self (the task type instance)Celery is the name of the current module, this only needed so names can be automatically generated when the tasks are defined in the __main__module.python学习笔记3-celery分布式任务处理器的更多相关文章
- Python学习笔记 - day14 - Celery异步任务
Celery概述 关于celery的定义,首先来看官方网站: Celery(芹菜) 是一个简单.灵活且可靠的,处理大量消息的分布式系统,并且提供维护这样一个系统的必需工具. 简单来看,是一个基于pyt ...
- 【目录】Python学习笔记
目录:Python学习笔记 目标:坚持每天学习,每周一篇博文 1. Python学习笔记 - day1 - 概述及安装 2.Python学习笔记 - day2 - PyCharm的基本使用 3.Pyt ...
- Python学习笔记,day5
Python学习笔记,day5 一.time & datetime模块 import本质为将要导入的模块,先解释一遍 #_*_coding:utf-8_*_ __author__ = 'Ale ...
- python学习笔记目录
人生苦短,我学python学习笔记目录: week1 python入门week2 python基础week3 python进阶week4 python模块week5 python高阶week6 数据结 ...
- python 学习笔记 13 -- 经常使用的时间模块之time
Python 没有包括相应日期和时间的内置类型.只是提供了3个相应的模块,能够採用多种表示管理日期和时间值: * time 模块由底层C库提供与时间相关的函数.它包括一些函数用于获取时钟时间和处 ...
- python学习笔记整理——字典
python学习笔记整理 数据结构--字典 无序的 {键:值} 对集合 用于查询的方法 len(d) Return the number of items in the dictionary d. 返 ...
- VS2013中Python学习笔记[Django Web的第一个网页]
前言 前面我简单介绍了Python的Hello World.看到有人问我搞搞Python的Web,一时兴起,就来试试看. 第一篇 VS2013中Python学习笔记[环境搭建] 简单介绍Python环 ...
- python学习笔记之module && package
个人总结: import module,module就是文件名,导入那个python文件 import package,package就是一个文件夹,导入的文件夹下有一个__init__.py的文件, ...
- python学习笔记(六)文件夹遍历,异常处理
python学习笔记(六) 文件夹遍历 1.递归遍历 import os allfile = [] def dirList(path): filelist = os.listdir(path) for ...
- python学习笔记--Django入门四 管理站点--二
接上一节 python学习笔记--Django入门四 管理站点 设置字段可选 编辑Book模块在email字段上加上blank=True,指定email字段为可选,代码如下: class Autho ...
随机推荐
- android首次点击没反应,第二次才反应
比如我写了个重置密码确认按钮的animation动画,动画代码都没问题,但等我输入密码,再点击这个确认按钮,动画没反应,第二次才反应 解决办法已经写到我的公众号,二维码在下面,欢迎关注,谢谢. 本人联 ...
- js封装的方法
1.JS封装就是尽量把使用的方式简单化,内部逻辑和使用解耦.通俗的说就是使用的时候只需要知道参数和返回值,其他条件尽量不要使用人员进行设置. 2.JS封装的方法有函数方式.对象的方式.闭包的方式. 举 ...
- Ubuntu下两个gcc版本切换
Ubuntu系统使用的gcc版本随着发布版本的不同而不同,在编译Android系统时不同的版本推荐用不同的gcc去编译,那么可不可以改变系统的gcc来适应android编译环境的需求呢?答案是可以的. ...
- LeetCode【217. Contains Duplicate】
Given an array of integers, find if the array contains any duplicates. Your function should return t ...
- ubuntu 编译安装 srilm
Ubuntu 64bit系统下SRILM的配置 依赖软件包(先进行): 1.c/c++ compiler:编译器gcc 3.4.3及以上版本,我的是gcc 4.4 2.GNU make:构建和管理工程 ...
- [转]SQLServer2008日志文件无法收缩处理方法
问题描述 发现有的数据库日志文件太大,无论如何收缩执行几次SQL语句都不行.事务日志达30+G,而且使用常规的截断.收缩方法均无法减小日志物理文件的尺寸,经过一番寻找,终于找到了解决方法. 查 ...
- System.Windows.Media.Imageing.BItmapImage 这么用才不会占用文件
// Read byte[] from png file BinaryReader binReader = new BinaryReader(File.Open(filepath, FileMode. ...
- IOCP之客户端及消息传递
上篇说到IOCP的精简实现,这篇来讲IOCP客户端和消息传递 在ConnectEx代码之前,CreateIoCompletionPort的第三个参数,把socket句柄+0x01000000作为传递 ...
- MSSQL 获取汉字全拼 和 汉字首字母
--获取全拼 DECLARE @str VARCHAR(max) SET @str= [dbo].[fn_Getquanpin]('中山') PRINT(@str) )) ) as begin ),) ...
- ADF_Desktop Integration系列1_ADF桌面集成入门之设定Development Environment
2013-05-01 Created By BaoXinjian