@ -137,7 +137,7 @@ class Job(object):
# dependency could be job instance or id
# dependency could be job instance or id
if depends_on is not None :
if depends_on is not None :
job . _dependency_id = depends_on . id if isinstance ( depends_on , Job ) else depends_on
job . _dependency_id s = [ depends_on . id if isinstance ( depends_on , Job ) else depends_on ]
return job
return job
def get_status ( self ) :
def get_status ( self ) :
@ -169,16 +169,24 @@ class Job(object):
def is_deferred ( self ) :
def is_deferred ( self ) :
return self . get_status ( ) == JobStatus . DEFERRED
return self . get_status ( ) == JobStatus . DEFERRED
@property
def _dependency_id ( self ) :
""" Returns the first item in self._dependency_ids. Present
preserve compatibility with third party packages . .
"""
if self . _dependency_ids :
return self . _dependency_ids [ 0 ]
@property
@property
def dependency ( self ) :
def dependency ( self ) :
""" Returns a job ' s dependency. To avoid repeated Redis fetches, we cache
""" Returns a job ' s dependency. To avoid repeated Redis fetches, we cache
job . dependency as job . _dependency .
job . dependency as job . _dependency .
"""
"""
if self . _dependency_id is None :
if not self . _dependency_id s:
return None
return None
if hasattr ( self , ' _dependency ' ) :
if hasattr ( self , ' _dependency ' ) :
return self . _dependency
return self . _dependency
job = self . fetch ( self . _dependency_id , connection = self . connection )
job = self . fetch ( self . _dependency_id s[ 0 ] , connection = self . connection )
self . _dependency = job
self . _dependency = job
return job
return job
@ -328,7 +336,7 @@ class Job(object):
self . failure_ttl = None
self . failure_ttl = None
self . ttl = None
self . ttl = None
self . _status = None
self . _status = None
self . _dependency_id = None
self . _dependency_id s = [ ]
self . meta = { }
self . meta = { }
def __repr__ ( self ) : # noqa # pragma: no cover
def __repr__ ( self ) : # noqa # pragma: no cover
@ -437,7 +445,10 @@ class Job(object):
self . result_ttl = int ( obj . get ( ' result_ttl ' ) ) if obj . get ( ' result_ttl ' ) else None # noqa
self . result_ttl = int ( obj . get ( ' result_ttl ' ) ) if obj . get ( ' result_ttl ' ) else None # noqa
self . failure_ttl = int ( obj . get ( ' failure_ttl ' ) ) if obj . get ( ' failure_ttl ' ) else None # noqa
self . failure_ttl = int ( obj . get ( ' failure_ttl ' ) ) if obj . get ( ' failure_ttl ' ) else None # noqa
self . _status = obj . get ( ' status ' ) if obj . get ( ' status ' ) else None
self . _status = obj . get ( ' status ' ) if obj . get ( ' status ' ) else None
self . _dependency_id = as_text ( obj . get ( ' dependency_id ' , None ) )
dependency_id = obj . get ( ' dependency_id ' , None )
self . _dependency_ids = [ as_text ( dependency_id ) ] if dependency_id else [ ]
self . ttl = int ( obj . get ( ' ttl ' ) ) if obj . get ( ' ttl ' ) else None
self . ttl = int ( obj . get ( ' ttl ' ) ) if obj . get ( ' ttl ' ) else None
self . meta = unpickle ( obj . get ( ' meta ' ) ) if obj . get ( ' meta ' ) else { }
self . meta = unpickle ( obj . get ( ' meta ' ) ) if obj . get ( ' meta ' ) else { }
@ -497,8 +508,8 @@ class Job(object):
obj [ ' failure_ttl ' ] = self . failure_ttl
obj [ ' failure_ttl ' ] = self . failure_ttl
if self . _status is not None :
if self . _status is not None :
obj [ ' status ' ] = self . _status
obj [ ' status ' ] = self . _status
if self . _dependency_id i s not None :
if self . _dependency_id s:
obj [ ' dependency_id ' ] = self . _dependency_id
obj [ ' dependency_id ' ] = self . _dependency_id s[ 0 ]
if self . meta and include_meta :
if self . meta and include_meta :
obj [ ' meta ' ] = dumps ( self . meta )
obj [ ' meta ' ] = dumps ( self . meta )
if self . ttl :
if self . ttl :
@ -683,7 +694,9 @@ class Job(object):
registry . add ( self , pipeline = pipeline )
registry . add ( self , pipeline = pipeline )
connection = pipeline if pipeline is not None else self . connection
connection = pipeline if pipeline is not None else self . connection
connection . sadd ( self . dependents_key_for ( self . _dependency_id ) , self . id )
for dependency_id in self . _dependency_ids :
dependents_key = self . dependents_key_for ( dependency_id )
connection . sadd ( dependents_key , self . id )
_job_stack = LocalStack ( )
_job_stack = LocalStack ( )