Commit 5544b59b authored by Loic Esteve's avatar Loic Esteve Committed by Hardik Juneja

Move class definitions inside ENABLE_JOBLIB block

parent bd51d473
...@@ -43,38 +43,38 @@ except ImportError: ...@@ -43,38 +43,38 @@ except ImportError:
LOG("CMFActivityBackend", WARNING, "CLASS NOT LOADED!!!") LOG("CMFActivityBackend", WARNING, "CLASS NOT LOADED!!!")
ENABLE_JOBLIB = False ENABLE_JOBLIB = False
class MySafeFunction(SafeFunction): if ENABLE_JOBLIB:
"""Wrapper around a SafeFunction that catches any exception class MySafeFunction(SafeFunction):
"""Wrapper around a SafeFunction that catches any exception
The exception can be handled in CMFActivityResult.get The exception can be handled in CMFActivityResult.get
""" """
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs):
try: try:
return super(MySafeFunction, self).__call__(*args, **kwargs) return super(MySafeFunction, self).__call__(*args, **kwargs)
except Exception as exc: except Exception as exc:
return exc return exc
class CMFActivityResult(object): class CMFActivityResult(object):
def __init__(self, active_process, callback): def __init__(self, active_process, callback):
self.active_process = active_process self.active_process = active_process
self.callback = callback self.callback = callback
def get(self, timeout=None): def get(self, timeout=None):
while not self.active_process.getResultList(): while not self.active_process.getResultList():
time.sleep(1) time.sleep(1)
if timeout is not None: if timeout is not None:
timeout -= 1 timeout -= 1
if timeout < 0: if timeout < 0:
raise RuntimeError('Timeout reached') raise RuntimeError('Timeout reached')
transaction.commit() transaction.commit()
result = self.active_process.getResultList()[0].result result = self.active_process.getResultList()[0].result
# TODO raise before or after the callback? # TODO raise before or after the callback?
if isinstance(result, Exception): if isinstance(result, Exception):
raise result raise result
if self.callback is not None: if self.callback is not None:
self.callback(result) self.callback(result)
return result return result
if ENABLE_JOBLIB:
class CMFActivityBackend(ParallelBackendBase): class CMFActivityBackend(ParallelBackendBase):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.zope_context = kwargs['zope_context'] self.zope_context = kwargs['zope_context']
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment