def form_for_activity(form): try: inputs = task_service.get_inputs(form['act_id']) outputs = task_service.get_outputs(form['act_id']) except Exception: subprocess_stack = form['subprocess_stack'] act_id = form['act_id'] instance_data = PipelineInstance.objects.get(instance_id=form['instance_id']).execution_data inputs = pipeline_parser.WebPipelineAdapter(instance_data).get_act_inputs(act_id=act_id, subprocess_stack=subprocess_stack) outputs = {} component = library.ComponentLibrary.get_component_class(form['component_code']) # append inputs inputs_table = inputs # append outputs outputs_table = [] outputs_format = component.outputs_format() for outputs_item in outputs_format: value = outputs.get('outputs', {}).get(outputs_item['key'], '') outputs_table.append({ 'name': outputs_item['name'], 'value': value }) data = { 'inputs': inputs_table, 'outputs': outputs_table, 'ex_data': outputs.get('ex_data', '') } return data
def start(self, executor): from pipeline.parser import pipeline_parser from pipeline.engine import api from pipeline.utils.context import get_pipeline_context from pipeline.engine.models import FunctionSwitch if FunctionSwitch.objects.is_frozen(): return False, 'engine has been freeze, try later please' with transaction.atomic(): instance = self.__class__.objects.select_for_update().get(id=self.id) if instance.is_started: return False, 'pipeline instance already started.' instance.start_time = timezone.now() instance.is_started = True instance.executor = executor # calculate tree info instance.calculate_tree_info() pipeline_data = instance.execution_data parser = pipeline_parser.WebPipelineAdapter(pipeline_data) pipeline = parser.parser(get_pipeline_context(instance, 'instance')) instance.save() api.start_pipeline(pipeline) return True, {}
def get_act_data(self, act_id, component_code=None, subprocess_stack=None): act_started = True result = True try: inputs = pipeline_api.get_inputs(act_id) outputs = pipeline_api.get_outputs(act_id) except Data.DoesNotExist: act_started = False if component_code: if not act_started: try: instance_data = self.pipeline_instance.execution_data inputs = pipeline_parser.WebPipelineAdapter( instance_data).get_act_inputs( act_id=act_id, subprocess_stack=subprocess_stack, root_pipeline_data=get_pipeline_context( self.pipeline_instance, 'instance')) outputs = {} except Exception as e: inputs = {} result = False message = 'parser pipeline tree error: %s' % e logger.exception(message) outputs = {'ex_data': message} outputs_table = [] try: component = library.ComponentLibrary.get_component_class( component_code) outputs_format = component.outputs_format() except Exception as e: result = False message = 'get component[component_code=%s] format error: %s' % ( component_code, e) logger.exception(message) outputs = {'ex_data': message} else: for outputs_item in outputs_format: value = outputs.get('outputs', {}).get(outputs_item['key'], '') outputs_table.append({ 'name': outputs_item['name'], 'value': value }) else: outputs_table = [] data = { 'inputs': inputs, 'outputs': outputs_table, 'ex_data': outputs.pop('ex_data', '') } return {'result': result, 'data': data, 'message': data['ex_data']}
def start(self, executor): from pipeline.parser import pipeline_parser from pipeline.engine import api from pipeline.utils.context import get_pipeline_context with transaction.atomic(): instance = self.__class__.objects.select_for_update().get( id=self.id) if instance.is_started: return False, 'pipeline instance already started.' instance.start_time = timezone.now() instance.is_started = True instance.executor = executor pipeline_data = instance.execution_data parser = pipeline_parser.WebPipelineAdapter(pipeline_data) pipeline = parser.parser(get_pipeline_context( instance, 'instance')) instance.save() api.start_pipeline(pipeline) return True, {}