我的 rq 任务运行正常,但获得所有工作的功能都不起作用——
$ pip3 freeze | egrep -i "rq|redis"
redis==2.10.6
rq==0.12.0
$ flask shell
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
App: app [production]
Instance: .../flask/instance
>>> from redis import Redis
>>> import rq
>>> q = rq.Queue('example-rq', connection=Redis.from_url('redis://'))
>>> job = q.enqueue('app.tasks.example', 100)
>>> job.get_id()
'93c0e279-3ce7-48c6-8f97-ace8a29ada70'
>>> q.job_ids
[]
>>> q.get_job_ids()
[]
>>> q.jobs
[]
示例任务非常基础——
$ cat app/tasks.py
from time import sleep
from rq import get_current_job
# duration in second
def example(duration):
job = get_current_job()
print("Starting task example " + job.get_id())
for i in range(duration):
job.meta['progress'] = 100.0 * i / duration
job.save_meta()
if i%5 == 0:
print(i)
sleep(1)
job.meta['progress'] = 100
job.save_meta()
print("Completed task example")
可能出了什么问题?顺便说一句,这是在 Ubuntu 18.04 下