class StepCall(StepBase): def __init__(self, name, application, step_type, step_subtype, step_content, shared_lock): super(StepCall, self).__init__(name, application, step_type, step_subtype, step_content, shared_lock) self.call_chain_name=step_subtype self.pycode = PyCode(self.name, 'inline(StepCall)', self.content[0]['value']) def run(self, runtime_context): assert(CTX_PAYLOAD in runtime_context) runtime_context[CTX_LOCK] = self.shared_lock chain = self.application.get_chain(self.call_chain_name) if not chain: raise SyntaxError('Chain "%s" does not exist!' % (self.call_chain_name,)) exception_queue = Queue.Queue() self.pycode.run( exception_queue, runtime_context) try: exception_info = exception_queue.get(block=False) raise RuntimeError(exception_info) except Queue.Empty: pass chain.run( runtime_context, False ) self.logger.info("StepCall runtime_contex[payload] %s", runtime_context[CTX_PAYLOAD])
class StepExceptionHandler(StepBase): def __init__(self, name, application, step_type, step_subtype, step_content, shared_lock): super(StepExceptionHandler, self).__init__(name, application, step_type, step_subtype, step_content, shared_lock) self.is_exception_handler = True self.call = None for instruction in step_content: if instruction['subtype'] == 'code': self.pycode = PyCode(self.name, 'inline', instruction['value']) elif instruction['subtype'] == 'gosub': self.call = instruction['value'] def run(self, runtime_context): self.logger.info('Executing ExceptionHandler "%s".', self.name) runtime_context[CTX_LOCK] = self.shared_lock exception_queue = Queue.Queue() self.pycode.run(exception_queue, runtime_context) try: exc_type, exc_obj, exc_trace = exception_queue.get(block=False) self.logger.error("%s Exception Info: %r", self.name, exc_obj) raise exc_obj except Queue.Empty: pass if self.call is not None: call_chain = self.application.get_chain(self.call) if not call_chain: raise SyntaxError('Chain "%s" does not exist!' % (self.call,)) call_chain.run( runtime_context, False )