add job.started_at

main
Samuel Colvin 9 years ago
parent ca235aee19
commit 082e61a212

@ -306,6 +306,7 @@ class Job(object):
self.description = None self.description = None
self.origin = None self.origin = None
self.enqueued_at = None self.enqueued_at = None
self.started_at = None
self.ended_at = None self.ended_at = None
self._result = None self._result = None
self.exc_info = None self.exc_info = None
@ -410,6 +411,7 @@ class Job(object):
self.origin = as_text(obj.get('origin')) self.origin = as_text(obj.get('origin'))
self.description = as_text(obj.get('description')) self.description = as_text(obj.get('description'))
self.enqueued_at = to_date(as_text(obj.get('enqueued_at'))) self.enqueued_at = to_date(as_text(obj.get('enqueued_at')))
self.started_at = to_date(as_text(obj.get('started_at')))
self.ended_at = to_date(as_text(obj.get('ended_at'))) self.ended_at = to_date(as_text(obj.get('ended_at')))
self._result = unpickle(obj.get('result')) if obj.get('result') else None # noqa self._result = unpickle(obj.get('result')) if obj.get('result') else None # noqa
self.exc_info = obj.get('exc_info') self.exc_info = obj.get('exc_info')
@ -432,6 +434,8 @@ class Job(object):
obj['description'] = self.description obj['description'] = self.description
if self.enqueued_at is not None: if self.enqueued_at is not None:
obj['enqueued_at'] = utcformat(self.enqueued_at) 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: if self.ended_at is not None:
obj['ended_at'] = utcformat(self.ended_at) obj['ended_at'] = utcformat(self.ended_at)
if self._result is not None: if self._result is not None:

@ -564,6 +564,7 @@ class Worker(object):
started_job_registry = StartedJobRegistry(job.origin, self.connection) started_job_registry = StartedJobRegistry(job.origin, self.connection)
try: try:
job.started_at = utcnow()
with self.death_penalty_class(job.timeout or self.queue_class.DEFAULT_TIMEOUT): with self.death_penalty_class(job.timeout or self.queue_class.DEFAULT_TIMEOUT):
rv = job.perform() rv = job.perform()

@ -54,6 +54,7 @@ class TestJob(RQTestCase):
# ...and nothing else # ...and nothing else
self.assertIsNone(job.origin) self.assertIsNone(job.origin)
self.assertIsNone(job.enqueued_at) self.assertIsNone(job.enqueued_at)
self.assertIsNone(job.started_at)
self.assertIsNone(job.ended_at) self.assertIsNone(job.ended_at)
self.assertIsNone(job.result) self.assertIsNone(job.result)
self.assertIsNone(job.exc_info) self.assertIsNone(job.exc_info)

@ -83,6 +83,29 @@ class TestWorker(RQTestCase):
'Expected at least some work done.') 'Expected at least some work done.')
self.assertEquals(job.result, 'Hi there, Frank!') self.assertEquals(job.result, 'Hi there, Frank!')
def assert_dt_between(self, dt, before, after):
if not before <= dt <= after: # pragma: no cover
raise AssertionError('Not %s <= %s <= %s' % (before, dt, after))
def test_job_times(self):
"""job times are set correctly."""
q = Queue('foo')
w = Worker([q])
before = utcnow()
before = before.replace(microsecond=0)
job = q.enqueue(say_hello)
self.assertIsNotNone(job.enqueued_at)
self.assertIsNone(job.started_at)
self.assertIsNone(job.ended_at)
self.assertEquals(w.work(burst=True), True,
'Expected at least some work done.')
self.assertEquals(job.result, 'Hi there, Stranger!')
after = utcnow()
job.refresh()
self.assert_dt_between(job.enqueued_at, before, after)
self.assert_dt_between(job.started_at, before, after)
self.assert_dt_between(job.ended_at, before, after)
def test_work_is_unreadable(self): def test_work_is_unreadable(self):
"""Unreadable jobs are put on the failed queue.""" """Unreadable jobs are put on the failed queue."""
q = Queue() q = Queue()

Loading…
Cancel
Save