Redis queue worker crashes in utcparse

杀马特。学长 韩版系。学妹 提交于 2021-01-29 16:13:11

问题


I'm trying to get a basic rq working following the tutorial at https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xxii-background-jobs.

I'm running on windows 10 WSL1 ubuntu 20.04.

I installed rq using sudo apt-get install python3-rq and rq is at version 1.2.2

I installed the python lib using pip3 install rq and this is then at version 1.4.0.

My worker code is in app/tasks.py and is

import time

def example():
    print('Starting task')
    for i in range(1..10):
        print(i)
        #time.sleep(1)
    print('Task completed')

When I do $ rq worker testrq this seems to start ok, and reports

   Worker rq:worker:6080c3a42475423895995e6da528ad2e: started, version 1.2.2
   *** Listening on testrq...
   Cleaning registries for queue: testrq

On another terminal I then start python3 and issue the commands:

>>> from redis import Redis
>>> import rq
>>> q = rq.Queue('testrq', connection=Redis.from_url('redis://'))
>>> job = q.enqueue('app.tasks.example')

When that last statement is entered the listening process reports the following, then exits:

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'

Can anyone please tell me how to fix this? Thanks

PS On searching the internet I did come across https://github.com/rq/rq/issues/927; not sure if this is related or not.


回答1:


Just in case someone has the some problem ...

I managed to get my Windows 10 OS upgraded and enabled WSL2. The task then ran ok, so I can only assume this was a bug in WSL1 somewhere.

Of course, it immediately highlighted my syntax error in range(1..10). Doh! Ruby may be gone, but clearly not forgotten!



来源:https://stackoverflow.com/questions/61808169/redis-queue-worker-crashes-in-utcparse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!