|
|
@ -1,6 +1,5 @@
|
|
|
|
import inspect
|
|
|
|
import inspect
|
|
|
|
from uuid import uuid4
|
|
|
|
from uuid import uuid4
|
|
|
|
from functools import wraps
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
from cPickle import loads, dumps, UnpicklingError
|
|
|
|
from cPickle import loads, dumps, UnpicklingError
|
|
|
|
except ImportError: # noqa
|
|
|
|
except ImportError: # noqa
|
|
|
@ -69,23 +68,6 @@ class Job(object):
|
|
|
|
|
|
|
|
|
|
|
|
data = None
|
|
|
|
data = None
|
|
|
|
|
|
|
|
|
|
|
|
def lazy(f, _attrs=[]):
|
|
|
|
|
|
|
|
attr = "_" + f.__name__
|
|
|
|
|
|
|
|
_attrs.append(attr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@wraps(f)
|
|
|
|
|
|
|
|
def decorator(job):
|
|
|
|
|
|
|
|
if job.data is not None:
|
|
|
|
|
|
|
|
payload = unpickle(job.data)
|
|
|
|
|
|
|
|
for name, value in zip(_attrs, payload):
|
|
|
|
|
|
|
|
setattr(job, name, value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
del job.data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return getattr(job, attr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return property(decorator)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Job construction
|
|
|
|
# Job construction
|
|
|
|
@classmethod
|
|
|
|
@classmethod
|
|
|
|
def create(cls, func, args=None, kwargs=None, connection=None,
|
|
|
|
def create(cls, func, args=None, kwargs=None, connection=None,
|
|
|
@ -169,26 +151,30 @@ class Job(object):
|
|
|
|
|
|
|
|
|
|
|
|
return import_attribute(self.func_name)
|
|
|
|
return import_attribute(self.func_name)
|
|
|
|
|
|
|
|
|
|
|
|
# Note: The order in which the following lazy attributes are
|
|
|
|
def _get_lazy(self, name):
|
|
|
|
# declared is important. Don't change!
|
|
|
|
if self.data is not None:
|
|
|
|
|
|
|
|
self._func_name, self._instance, self._args, self._kwargs = \
|
|
|
|
|
|
|
|
unpickle(self.data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
del self.data
|
|
|
|
|
|
|
|
|
|
|
|
@lazy
|
|
|
|
return getattr(self, "_" + name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
def func_name(self):
|
|
|
|
def func_name(self):
|
|
|
|
return self._func_name
|
|
|
|
return self._get_lazy('func_name')
|
|
|
|
|
|
|
|
|
|
|
|
@lazy
|
|
|
|
@property
|
|
|
|
def instance(self):
|
|
|
|
def instance(self):
|
|
|
|
return self._instance
|
|
|
|
return self._get_lazy('instance')
|
|
|
|
|
|
|
|
|
|
|
|
@lazy
|
|
|
|
@property
|
|
|
|
def args(self):
|
|
|
|
def args(self):
|
|
|
|
return self._args
|
|
|
|
return self._get_lazy('args')
|
|
|
|
|
|
|
|
|
|
|
|
@lazy
|
|
|
|
@property
|
|
|
|
def kwargs(self):
|
|
|
|
def kwargs(self):
|
|
|
|
return self._kwargs
|
|
|
|
return self._get_lazy('kwargs')
|
|
|
|
|
|
|
|
|
|
|
|
del lazy
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@classmethod
|
|
|
|
def exists(cls, job_id, connection=None):
|
|
|
|
def exists(cls, job_id, connection=None):
|
|
|
|