diff --git a/rq/job.py b/rq/job.py index 8e15224..69c18e1 100644 --- a/rq/job.py +++ b/rq/job.py @@ -531,10 +531,9 @@ class Job(object): obj['description'] = self.description if self.enqueued_at is not None: obj['enqueued_at'] = utcformat(self.enqueued_at) - if self.started_at is not None: - obj['started_at'] = utcformat(self.started_at) - if self.ended_at is not None: - obj['ended_at'] = utcformat(self.ended_at) + + obj['started_at'] = utcformat(self.started_at) if self.started_at else '' + obj['ended_at'] = utcformat(self.ended_at) if self.ended_at else '' if self._result is not None: try: obj['result'] = dumps(self._result) diff --git a/rq/registry.py b/rq/registry.py index eb45682..fa052d5 100644 --- a/rq/registry.py +++ b/rq/registry.py @@ -214,11 +214,16 @@ class FailedJobRegistry(BaseRegistry): result = self.connection.zrem(self.key, job.id) if not result: raise InvalidJobOperation - - queue = Queue(job.origin, connection=self.connection, - job_class=self.job_class) - - return queue.enqueue_job(job) + + with self.connection.pipeline() as pipeline: + queue = Queue(job.origin, connection=self.connection, + job_class=self.job_class) + job.started_at = None + job.ended_at = None + job.save() + job = queue.enqueue_job(job, pipeline=pipeline) + pipeline.execute() + return job class DeferredJobRegistry(BaseRegistry): diff --git a/rq/utils.py b/rq/utils.py index 0f63125..0058ce4 100644 --- a/rq/utils.py +++ b/rq/utils.py @@ -226,7 +226,7 @@ def backend_class(holder, default_name, override=None): def str_to_date(date_str): - if date_str is None: + if not date_str: return else: return utcparse(as_text(date_str)) diff --git a/tests/test_job.py b/tests/test_job.py index cd4241c..a7a1b27 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -219,7 +219,7 @@ class TestJob(RQTestCase): # ... and no other keys are stored self.assertEqual( sorted(self.testconn.hkeys(job.key)), - [b'created_at', b'data', b'description']) + [b'created_at', b'data', b'description', b'ended_at', b'started_at']) def test_persistence_of_parent_job(self): """Storing jobs with parent job, either instance or key.""" diff --git a/tests/test_registry.py b/tests/test_registry.py index 0fb50bc..cc1f4e7 100644 --- a/tests/test_registry.py +++ b/tests/test_registry.py @@ -356,6 +356,8 @@ class TestFailedJobRegistry(RQTestCase): job.refresh() self.assertEqual(job.get_status(), JobStatus.QUEUED) + self.assertEqual(job.started_at, None) + self.assertEqual(job.ended_at, None) worker.work(burst=True) self.assertTrue(job in registry)