redis python3 rq worker fails for utcparse started_at date absence

651 Views Asked by At

I have redis installed and running (Redis version=6.0.9 on a Ubuntu 18.04 machine) and followed this simple guide to schedule a job with rq but as soon as I launch app.py redis worker fails with:

10:31:17 RQ worker u'rq:worker:c73feeafc20f4f0c8baff1e5225e73f1' started, version 1.0
10:31:17 *** Listening on default...
10:31:18 Worker c73feeafc20f4f0c8baff1e5225e73f1: found an unhandled exception, quitting...
Traceback (most recent call last):
  File "/home/enrico/.local/lib/python2.7/site-packages/rq/worker.py", line 470, in work
    result = self.dequeue_job_and_maintain_ttl(timeout)
  File "/home/enrico/.local/lib/python2.7/site-packages/rq/worker.py", line 514, in dequeue_job_and_maintain_ttl
    job_class=self.job_class)
  File "/home/enrico/.local/lib/python2.7/site-packages/rq/queue.py", line 468, in dequeue_any
    job = job_class.fetch(job_id, connection=connection)
  File "/home/enrico/.local/lib/python2.7/site-packages/rq/job.py", line 287, in fetch
    job.refresh()
  File "/home/enrico/.local/lib/python2.7/site-packages/rq/job.py", line 428, in refresh
    self.started_at = to_date(as_text(obj.get('started_at')))
  File "/home/enrico/.local/lib/python2.7/site-packages/rq/job.py", line 411, in to_date
    return utcparse(as_text(date_str))
  File "/home/enrico/.local/lib/python2.7/site-packages/rq/utils.py", line 175, in utcparse
    return datetime.datetime.strptime(string, '%Y-%m-%dT%H:%M:%SZ')
  File "/usr/lib/python2.7/_strptime.py", line 332, in _strptime
    (data_string, format))
ValueError: time data '' does not match format '%Y-%m-%dT%H:%M:%SZ'

Here tasks.py:

from datetime import datetime, timedelta
import time

def print_task(seconds):
    print("Starting task")
    for num in range(seconds):
        print(num, ". Hello World!")
        time.sleep(1)
    print("Task completed")

def print_numbers(seconds):
    print("Starting num task")
    for num in range(seconds):
        print(num)
        time.sleep(1)
    print("Task to print_numbers completed")

Here app.py:

from datetime import datetime, timedelta
import time
from redis import Redis
from rq import Queue
import tasks

queue = Queue(connection=Redis())

def queue_tasks():
    queue.enqueue(tasks.print_task, 5)
    queue.enqueue_in(timedelta(seconds=10), tasks.print_numbers, 5)

def main():
    queue_tasks()

if __name__ == "__main__":
    main()

Here the commands I used:

python3.8 -m venv venv
source venv/bin/activate
pip install rq   ### Successfully installed click-7.1.2 redis-3.5.3 rq-1.7.0
python app.py

I open a second window and run rq worker and I got the fail in the first part of this post.

I tried to google around but this post just said that he updated his windows OS, this that was a resolved bug...does anybody got a clue on how to solve this?

0

There are 0 best solutions below