Python简单作业队列系统:RQ

jopen 9年前

RQ (Redis Queue) 是一个简单的 Python 库,用于实现作业的队列,并在后台进行处理。后端基于 Redis ,可方便集成到 Web 应用中,要求 Redis >= 2.6.0。

Getting started

首先,运行一个Redis服务器:

$ redis-server

将 jobs 加到队列中

import requests    def count_words_at_url(url):      """Just an example function that's called async."""      resp = requests.get(url)      return len(resp.text.split())

然后,创建一个RQ列队:

from rq import Queue, use_connection  use_connection()  q = Queue()

And enqueue the function call:

from my_module import count_words_at_url  result = q.enqueue(count_words_at_url, 'http://nvie.com')
 

项目主页:http://www.open-open.com/lib/view/home/1423984582562