Redis 队列工作线程在 UTCparse 中崩溃



我正在尝试按照 https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xxii-background-jobs 的教程获得基本的rq工作。

我运行在Windows 10 WSL1 ubuntu 20.04上。

我使用sudo apt-get install python3-rq安装了 rq,rq 的版本为 1.2.2

我使用pip3 install rq安装了 python 库,然后是 1.4.0 版。

我的工作线程代码位于应用/任务中.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; 不确定这是否相关。

以防万一有人遇到问题...

我设法升级了我的Windows 10操作系统并启用了WSL2。然后任务运行正常,所以我只能假设这是 WSL1 中某个地方的错误。

当然,它立即突出显示了我在range(1..10)中的语法错误。咚!Ruby 可能已经消失了,但显然没有被遗忘!

最新更新