|
|
@ -291,11 +291,8 @@ class Job(object):
|
|
|
|
self._status = as_text(obj.get('status') if obj.get('status') else None)
|
|
|
|
self._status = as_text(obj.get('status') if obj.get('status') else None)
|
|
|
|
self.meta = unpickle(obj.get('meta')) if obj.get('meta') else {}
|
|
|
|
self.meta = unpickle(obj.get('meta')) if obj.get('meta') else {}
|
|
|
|
|
|
|
|
|
|
|
|
def save(self, pipeline=None):
|
|
|
|
def dump(self):
|
|
|
|
"""Persists the current job instance to its corresponding Redis key."""
|
|
|
|
"""Returns a serialization of the current job instance"""
|
|
|
|
key = self.key
|
|
|
|
|
|
|
|
connection = pipeline if pipeline is not None else self.connection
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
obj = {}
|
|
|
|
obj = {}
|
|
|
|
obj['created_at'] = times.format(self.created_at or times.now(), 'UTC')
|
|
|
|
obj['created_at'] = times.format(self.created_at or times.now(), 'UTC')
|
|
|
|
|
|
|
|
|
|
|
@ -322,7 +319,14 @@ class Job(object):
|
|
|
|
if self.meta:
|
|
|
|
if self.meta:
|
|
|
|
obj['meta'] = dumps(self.meta)
|
|
|
|
obj['meta'] = dumps(self.meta)
|
|
|
|
|
|
|
|
|
|
|
|
connection.hmset(key, obj)
|
|
|
|
return obj
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def save(self, pipeline=None):
|
|
|
|
|
|
|
|
"""Persists the current job instance to its corresponding Redis key."""
|
|
|
|
|
|
|
|
key = self.key
|
|
|
|
|
|
|
|
connection = pipeline if pipeline is not None else self.connection
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connection.hmset(key, self.dump())
|
|
|
|
|
|
|
|
|
|
|
|
def cancel(self):
|
|
|
|
def cancel(self):
|
|
|
|
"""Cancels the given job, which will prevent the job from ever being
|
|
|
|
"""Cancels the given job, which will prevent the job from ever being
|
|
|
@ -379,13 +383,13 @@ class Job(object):
|
|
|
|
- If it's a positive number, set the job to expire in X seconds.
|
|
|
|
- If it's a positive number, set the job to expire in X seconds.
|
|
|
|
- If result_ttl is negative, don't set an expiry to it (persist
|
|
|
|
- If result_ttl is negative, don't set an expiry to it (persist
|
|
|
|
forever)
|
|
|
|
forever)
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
if ttl == 0:
|
|
|
|
if ttl == 0:
|
|
|
|
self.cancel()
|
|
|
|
self.cancel()
|
|
|
|
elif ttl > 0:
|
|
|
|
elif ttl > 0:
|
|
|
|
connection = pipeline if pipeline is not None else self.connection
|
|
|
|
connection = pipeline if pipeline is not None else self.connection
|
|
|
|
connection.expire(self.key, ttl)
|
|
|
|
connection.expire(self.key, ttl)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
def __str__(self):
|
|
|
|
return '<Job %s: %s>' % (self.id, self.description)
|
|
|
|
return '<Job %s: %s>' % (self.id, self.description)
|
|
|
|