[qa] attempt to fix #58.

This commit is contained in:
Romain Dorgueil
2017-05-22 19:17:34 +02:00
parent 54d2f73b35
commit cf21c0e088
2 changed files with 11 additions and 15 deletions

View File

@ -8,6 +8,12 @@ from bonobo.plugins import get_enhancers
from bonobo.util.errors import print_error from bonobo.util.errors import print_error
from bonobo.util.objects import Wrapper, get_name from bonobo.util.objects import Wrapper, get_name
@contextmanager
def recoverable(error_handler):
try:
yield
except Exception as exc: # pylint: disable=broad-except
error_handler(exc, traceback.format_exc())
@contextmanager @contextmanager
def unrecoverable(error_handler): def unrecoverable(error_handler):
@ -17,7 +23,6 @@ def unrecoverable(error_handler):
error_handler(exc, traceback.format_exc()) error_handler(exc, traceback.format_exc())
raise # raise unrecoverableerror from x ? raise # raise unrecoverableerror from x ?
class LoopingExecutionContext(Wrapper): class LoopingExecutionContext(Wrapper):
alive = True alive = True
PERIOD = 0.25 PERIOD = 0.25

View File

@ -1,6 +1,4 @@
import traceback from bonobo.execution.base import LoopingExecutionContext, recoverable
from bonobo.execution.base import LoopingExecutionContext
class PluginExecutionContext(LoopingExecutionContext): class PluginExecutionContext(LoopingExecutionContext):
@ -14,21 +12,14 @@ class PluginExecutionContext(LoopingExecutionContext):
def start(self): def start(self):
super().start() super().start()
try: with recoverable(self.handle_error):
self.wrapped.initialize() self.wrapped.initialize()
except Exception as exc: # pylint: disable=broad-except
self.handle_error(exc, traceback.format_exc())
def shutdown(self): def shutdown(self):
try: with recoverable(self.handle_error):
self.wrapped.finalize() self.wrapped.finalize()
except Exception as exc: # pylint: disable=broad-except self.alive = False
self.handle_error(exc, traceback.format_exc())
finally:
self.alive = False
def step(self): def step(self):
try: with recoverable(self.handle_error):
self.wrapped.run() self.wrapped.run()
except Exception as exc: # pylint: disable=broad-except
self.handle_error(exc, traceback.format_exc())