使用mongo作为后端存储的队列。

mongoqueue的Python项目详细描述


属性

  • Isolation

    Do not let different consumers process the same message.

  • Reliablity

    Do not let a failed consumer disappear an item.

  • Atomic

    Operations on the queue are atomic.

用法

队列可以用mongo集合和使用者实例化 标识符。使用者标识符有助于区分多个队列 正在从队列中获取作业的消费者:

>> from pymongo import Connection
>> from mongoqueue import MongoQueue
>> queue = MongoQueue(
...   Connection(TEST_DB).doctest_queue,
...   consumer_id="consumer-1",
...   timeout=300,
...   max_attempts=3)

MongoQueuetimeout参数指定 seconds a一个作业在其 被认为是失败的。

超时或错误超过^{tt3}的作业$ 参数被认为是永久失败的,并且将不再是 处理。

可以通过传递字典将新作业/项放入队列:

>> queue.put({"foobar": 1})

作业priority键和整数值可以在 将导致作业在下一步之前处理的字典 优先项目:

>> queue.put({"foobar": 0}, priority=1})

通过调用队列上的next方法可以取出项。 这将返回作业对象:

>> job = queue.next()
>> job.payload
{"foobar": 1}

job类公开作业上的一些控制方法,用于标记进度, 完成、错误或将作业释放回队列中。

  • ^{tt6}$ Marks a job as complete and removes it from the queue.
  • ^{tt7}$ Optionally specified with a message, releases the job back to the
    queue, and increments its attempts, and stores the error message on the job.
  • ^{tt8}$ Optionally takes a progress count integer, notes progress on the job
    and resets the lock timeout.
  • ^{tt9}$ Release a job back to the pool. The attempts counter is not modified.

为方便起见,该作业支持上下文管理器协议:

>> with job as data:
...   print data['payload']

{"foobar: 0}

如果上下文关闭被退出而没有作业被标记为完整的, 如果有异常,错误将存储在作业中。

运行测试

单元测试可以使用

$ python setup.py nosetests

更改

0.6.0-2013年2月4日-将传入的数据与作业中的元数据隔离。 0.5.2-2012年12月9日-修复来自Pymongo 2.4的排序参数中的回归 0.5.1-2012年12月2日-Readme数据文件的打包修复程序。

学分

Kapil Thangavelu,作者和维护者 Dustin Laurence,Pymongo 2.4的排序修复 Jonathan Sackett,工作数据隔离。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
空字符串检查在java中未按预期工作   JavaSpringWebClient:自动计算主体的HMAC签名并将其作为头传递   foreach是否有一个Java等效的foreach循环和一个引用变量?   java如何在Eclipse中导入jar   使用特定第三方或java时lombok触发错误。*方法或构造函数   安卓 java将对象数组转换为int数组   java使一定百分比的JUnit测试通过   java Android:将Seekbar的一个值与另一个值进行比较   java将int数组(图像数据)写入文件的最佳方式是什么   java取代了系统。yml的构造函数内的getProperty   sqlite Java将公钥和私钥转换为字符串,然后再转换回字符串   安卓获取白色像素并将其保存到java opencv中的数组中   java为什么是ServerSocket。setSocketFactory静态?   Java数组似乎在不直接修改的情况下更改值