如何从Redis中在rq中排队一个任务
我需要从mysql数据库中获取一些函数和它们执行的时间,然后把这些信息保存到redis里。接下来,我想从redis中按照规定的时间来执行这些函数。我想用rq这个工具来做调度,但我还不知道应该用什么样的格式把导入的数据保存到redis中。其实我对python和redis都很陌生。
1 个回答
1
如果你安装了redis,会有一个文件(对我来说是 ~/lib/python2.7/site-packages/rq/queue.py,这个文件又会调用job.py),里面清楚地说明了enqueue和enqueue_call这两个函数的作用:
def enqueue_call(self, func, args=None, kwargs=None,
timeout=None, result_ttl=None, description=None,
depends_on=None):
"""Creates a job to represent the delayed function call and enqueues it.
It is much like `.enqueue()`, except that it takes the function's args
and kwargs as explicit arguments. Any kwargs passed to this function
contain options for RQ itself.
etc...."""
def enqueue(self, f, *args, **kwargs):
"""Creates a job to represent the delayed function call and enqueues it.
Expects the function to call, along with the arguments and keyword
arguments.
etc...."""