Redis 队列工作程序在 utcparse 中崩溃

2024-05-22

我正在尝试按照以下教程获得基本的 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-rqrq 版本为 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;不确定这是否相关。


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

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Redis 队列工作程序在 utcparse 中崩溃 的相关文章

随机推荐