我正在尝试按照以下教程获得基本的 rq 工作:https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xxii-background-jobs https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xxii-background-jobs.
我在 Windows 10 WSL1 ubuntu 20.04 上运行。
我使用安装了 rqsudo apt-get install python3-rq
rq 版本为 1.2.2
我使用安装了 python libpip3 install rq
这是 1.4.0 版本。
我的工作人员代码位于 app/tasks.py 中,并且是
import time
def example():
print('Starting task')
for i in range(1..10):
print(i)
#time.sleep(1)
print('Task completed')
当我做$ rq worker testrq
这似乎开始正常,并报告
Worker rq:worker:6080c3a42475423895995e6da528ad2e: started, version 1.2.2
*** Listening on testrq...
Cleaning registries for queue: testrq
然后在另一个终端上启动 python3 并发出命令:
>>> from redis import Redis
>>> import rq
>>> q = rq.Queue('testrq', connection=Redis.from_url('redis://'))
>>> job = q.enqueue('app.tasks.example')
当输入最后一条语句时,侦听进程会报告以下内容,然后退出:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/rq/utils.py", line 169, in utcparse
return datetime.datetime.strptime(string, _TIMESTAMP_FORMAT)
File "/usr/lib/python3.8/_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/usr/lib/python3.8/_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data '' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/rq/worker.py", line 508, in work
result = self.dequeue_job_and_maintain_ttl(timeout)
File "/usr/lib/python3/dist-packages/rq/worker.py", line 574, in dequeue_job_and_maintain_ttl
result = self.queue_class.dequeue_any(self.queues, timeout,
File "/usr/lib/python3/dist-packages/rq/queue.py", line 539, in dequeue_any
job = job_class.fetch(job_id, connection=connection)
File "/usr/lib/python3/dist-packages/rq/job.py", line 303, in fetch
job.refresh()
File "/usr/lib/python3/dist-packages/rq/job.py", line 515, in refresh
self.restore(data)
File "/usr/lib/python3/dist-packages/rq/job.py", line 478, in restore
self.started_at = str_to_date(obj.get('started_at'))
File "/usr/lib/python3/dist-packages/rq/utils.py", line 256, in str_to_date
return utcparse(as_text(date_str))
File "/usr/lib/python3/dist-packages/rq/utils.py", line 172, in utcparse
return datetime.datetime.strptime(string, '%Y-%m-%dT%H:%M:%SZ')
File "/usr/lib/python3.8/_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/usr/lib/python3.8/_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data '' does not match format '%Y-%m-%dT%H:%M:%SZ'
谁能告诉我如何解决这个问题?谢谢
PS 在网上搜索时我确实遇到了https://github.com/rq/rq/issues/927 https://github.com/rq/rq/issues/927;不确定这是否相关。