def handle(self, process, element, status): # rerun mode if status.loop > 1: element.prepare_rerun_data() element.pipeline.context.recover_variable() process.top_pipeline.context.recover_variable() # set loop count element.data.outputs._loop = status.loop - 1 # pre output extract process.top_pipeline.context.extract_output(element) # hydrate data hydrate_node_data(element) # context injection data = element.pipeline.data context = element.pipeline.context for k, v in data.get_inputs().items(): context.set_global_var(k, v) hydrated = hydrate_data(context.variables) context.update_global_var(hydrated) sub_pipeline = element.pipeline process.push_pipeline(sub_pipeline, is_subprocess=True) return self.HandleResult(next_node=sub_pipeline.start_event, should_return=False, should_sleep=False)
def get_act_inputs(self, act_id, subprocess_stack=None, root_pipeline_data=None): act = self.get_act(act_id, subprocess_stack, root_pipeline_data) hydrate_node_data(act) inputs = act.data.inputs return inputs
def subprocess_handler(process, subprocess_act): # hydrate data hydrate_node_data(subprocess_act) # context injection data = subprocess_act.pipeline.data context = subprocess_act.pipeline.context() for k, v in data.get_inputs().items(): context.set_global_var(k, v) hydrated = hydrate_data(context.variables) context.update_global_var(hydrated) sub_pipeline = subprocess_act.pipeline process.push_pipeline(sub_pipeline, is_subprocess=True) return HandleResult(next_node=sub_pipeline.start_event(), should_return=False, should_sleep=False)
def handle(self, process, element, status): success = False exception_occurred = False monitoring = False version = status.version root_pipeline = process.root_pipeline # rerun mode if status.loop > 1 and not element.on_retry(): element.prepare_rerun_data() process.top_pipeline.context.recover_variable() elif element.on_retry(): element.retry_at_current_exec() # set loop to data element.data.inputs._loop = status.loop - 1 element.data.outputs._loop = status.loop - 1 # pre output extract process.top_pipeline.context.extract_output(element) # hydrate inputs hydrate_node_data(element) if element.timeout: logger.info('node %s %s start timeout monitor, timeout: %s' % (element.id, version, element.timeout)) signals.service_activity_timeout_monitor_start.send( sender=element.__class__, node_id=element.id, version=version, root_pipeline_id=root_pipeline.id, countdown=element.timeout) monitoring = True # execute service try: success = element.execute(root_pipeline.data) except Exception as e: if element.error_ignorable: # ignore exception success = True exception_occurred = True element.ignore_error() ex_data = traceback.format_exc(e) element.data.outputs.ex_data = ex_data logger.error(ex_data) # process result if success is False: ex_data = element.data.get_one_of_outputs('ex_data') Status.objects.fail(element, ex_data) try: element.failure_handler(root_pipeline.data) except Exception as e: logger.error('failure_handler(%s) failed: %s' % (element.id, traceback.format_exc(e))) if monitoring: signals.service_activity_timeout_monitor_end.send( sender=element.__class__, node_id=element.id, version=version) logger.info('node %s %s timeout monitor revoke' % (element.id, version)) # send activity error signal valve.send(signals, 'activity_failed', sender=root_pipeline, pipeline_id=root_pipeline.id, pipeline_activity_id=element.id, subprocess_id_stack=process.subprocess_stack) return self.HandleResult(next_node=None, should_return=False, should_sleep=True) else: is_error_ignored = element.error_ignorable and not element.get_result_bit( ) if element.need_schedule( ) and not exception_occurred and not is_error_ignored: # write data before schedule Data.objects.write_node_data(element) # set schedule ScheduleService.objects.set_schedule( element.id, service_act=element.shell(), process_id=process.id, version=version, parent_data=process.top_pipeline.data) return self.HandleResult(next_node=None, should_return=True, should_sleep=True) process.top_pipeline.context.extract_output(element) error_ignorable = not element.get_result_bit() if monitoring: signals.service_activity_timeout_monitor_end.send( sender=element.__class__, node_id=element.id, version=version) logger.info('node %s %s timeout monitor revoke' % (element.id, version)) if not Status.objects.finish(element, error_ignorable): # has been forced failed return self.HandleResult(next_node=None, should_return=False, should_sleep=True) return self.HandleResult(next_node=element.next(), should_return=False, should_sleep=False)
def loop_service_activity_handler(process, loop_service_act): success = False error_occurred = False ex_data = None # prepare data is_retrying = getattr(loop_service_act, 'retrying', False) setattr(loop_service_act, 'retrying', None) if not is_retrying: loop_service_act.prepare_loop_data() # hydrate inputs hydrate_node_data(loop_service_act) try: success = loop_service_act.execute(process.root_pipeline.data) except Exception as e: if loop_service_act.error_ignorable: success = True error_occurred = True loop_service_act.ignore_error() else: # send activity error signal valve.send(signals, 'activity_failed', sender=process.root_pipeline, pipeline_id=process.root_pipeline.id, pipeline_activity_id=loop_service_act.id) ex_data = traceback.format_exc(e) loop_service_act.data.set_outputs('ex_data', ex_data) logger.error(ex_data) if not success: ex_data = loop_service_act.data.get_one_of_outputs('ex_data') Status.objects.fail(loop_service_act, ex_data) LoopActivityHistory.objects.record(loop_service_act) LoopActivityStatus.objects.refresh_status(loop_service_act) try: loop_service_act.failure_handler(process.root_pipeline.data) except Exception as e: logger.error('failure_handler(%s) failed: %s' % (loop_service_act.id, traceback.format_exc(e))) # send activity error signal valve.send(signals, 'activity_failed', sender=process.root_pipeline, pipeline_id=process.root_pipeline.id, pipeline_activity_id=loop_service_act.id) return HandleResult(next_node=None, should_return=False, should_sleep=True) else: if loop_service_act.need_schedule() and not error_occurred: version = Status.objects.get(id=loop_service_act.id).version ScheduleService.objects.set_schedule( loop_service_act.id, service_act=loop_service_act.shell(), process_id=process.id, version=version, parent_data=process.top_pipeline.data) return HandleResult(next_node=None, should_return=True, should_sleep=True) process.top_pipeline.context().extract_output(loop_service_act) if not Status.objects.finish(loop_service_act): # has been forced failed # ignore_error have been called if error_occurred: loop_service_act.revert_ignore_error() LoopActivityHistory.objects.record(loop_service_act) return HandleResult(next_node=None, should_return=False, should_sleep=True) LoopActivityHistory.objects.record(loop_service_act) loop_service_act.loop_success() LoopActivityStatus.objects.refresh_status(loop_service_act) return HandleResult(next_node=loop_service_act.next(), should_return=False, should_sleep=False)
def service_activity_handler(process, service_act): success = False exception_occurred = False monitoring = False version = Status.objects.get(id=service_act.id).version root_pipeline = process.root_pipeline # rerun mode if Status.objects.get(id=service_act.id).loop > 1: service_act.prepare_rerun_data() # hydrate inputs hydrate_node_data(service_act) if service_act.timeout: logger.info('node %s %s start timeout monitor, timeout: %s' % (service_act.id, version, service_act.timeout)) signals.service_activity_timeout_monitor_start.send( sender=service_act.__class__, node_id=service_act.id, version=version, root_pipeline_id=root_pipeline.id, countdown=service_act.timeout) monitoring = True # execute service try: success = service_act.execute(root_pipeline.data) except Exception as e: if service_act.error_ignorable: # ignore exception success = True exception_occurred = True service_act.ignore_error() else: # send activity error signal valve.send(signals, 'activity_failed', sender=root_pipeline, pipeline_id=root_pipeline.id, pipeline_activity_id=service_act.id) ex_data = traceback.format_exc(e) service_act.data.set_outputs('ex_data', ex_data) logger.error(ex_data) # process result if success is False: ex_data = service_act.data.get_one_of_outputs('ex_data') Status.objects.fail(service_act, ex_data) try: service_act.failure_handler(root_pipeline.data) except Exception as e: logger.error('failure_handler(%s) failed: %s' % (service_act.id, traceback.format_exc(e))) if monitoring: signals.service_activity_timeout_monitor_end.send( sender=service_act.__class__, node_id=service_act.id, version=version) logger.info('node %s %s timeout monitor revoke' % (service_act.id, version)) # send activity error signal valve.send(signals, 'activity_failed', sender=root_pipeline, pipeline_id=root_pipeline.id, pipeline_activity_id=service_act.id) return HandleResult(next_node=None, should_return=False, should_sleep=True) else: is_error_ignored = service_act.error_ignorable and not service_act.get_result_bit( ) if service_act.need_schedule( ) and not exception_occurred and not is_error_ignored: # write data before schedule Data.objects.write_node_data(service_act) # set schedule ScheduleService.objects.set_schedule( service_act.id, service_act=service_act.shell(), process_id=process.id, version=version, parent_data=process.top_pipeline.data) return HandleResult(next_node=None, should_return=True, should_sleep=True) process.top_pipeline.context().extract_output(service_act) error_ignorable = not service_act.get_result_bit() if monitoring: signals.service_activity_timeout_monitor_end.send( sender=service_act.__class__, node_id=service_act.id, version=version) logger.info('node %s %s timeout monitor revoke' % (service_act.id, version)) if not Status.objects.finish(service_act, error_ignorable): # has been forced failed return HandleResult(next_node=None, should_return=False, should_sleep=True) return HandleResult(next_node=service_act.next(), should_return=False, should_sleep=False)