我正在尝试测试排队的 redis 作业,但meta
数据似乎没有在任务和发起者之间传递。job_id 似乎匹配,所以我很困惑。也许一些新鲜的眼睛可以帮助我解决问题:
任务是根据文档:
from rq import get_current_job
def do_test(word):
job = get_current_job()
print job.get_id()
job.meta['word'] = word
job.save()
print "saved: ", job.meta['word']
return True
rqworker
日志保存后打印job_id和word
14:32:32 *** Listening on default...
14:33:07 default: labeller.do_test('supercalafragelistic') (a6e2e579-df26-411a-b017-8788d621149f)
a6e2e579-df26-411a-b017-8788d621149f
saved: supercalafragelistic
14:33:07 Job OK, result = True
14:33:07 Result is kept for 500 seconds.
该任务是从单元测试中调用的:
class RedisQueueTestCase(unittest.TestCase):
"""
Requires running "rqworker" on the localhost cmdline
"""
def setUp(self):
use_connection()
self.q = Queue()
def test_enqueue(self):
job = self.q.enqueue(do_test, "supercalafragelistic")
while True:
print job.get_id(), job.get_status(), job.meta.get('word')
if job.is_finished:
print "Result: ", job.result, job.meta.get('word')
break
time.sleep(0.25)
并生成此日志,显示相同的 job_id 和正确的结果,但永远不会填充meta
变量。word
Testing started at 2:33 PM ...
a6e2e579-df26-411a-b017-8788d621149f queued None
a6e2e579-df26-411a-b017-8788d621149f finished None
Result: True None
Process finished with exit code 0
我尝试添加很长的延迟,以便日志有机会看到任务started
,但未完成状态(以防元在完成时被清除),但它没有任何区别。
知道我错过了什么吗?