def post(self, request, action=None, business_id=None): data = Q2D_POST(request) taskflow = Taskflow().get_one( {"_id": ObjectId(data.get("instance_id"))}) if action == "start": pipeline_data = json.loads(taskflow.get("pipeline_tree")) pipeline_data['id'] = taskflow.get('_id') pipeline_data['name'] = taskflow.get('name') if pipeline_data.get("data") is None: pipeline_data['data'] = {"inputs": {}, "outputs": {}} parser_obj = PipelineParser(pipeline_data) pipeline = parser_obj.parser() act_result = task_service.run_pipeline( pipeline, instance_id=taskflow.get('_id')) return Response({"result": True})
def test_sub_process_parser(self): parser_obj = PipelineParser(PIPELINE_WITH_SUB_PROCESS) self.assertIsInstance(parser_obj.parser(), Pipeline)
def test_pipeline_parser(self): parser_obj = PipelineParser(PIPELINE_DATA) self.assertIsInstance(parser_obj.parser(), Pipeline)
def main_test(): id_list = [node_uniqid() for i in xrange(100)] pipe1 = { 'id': id_list[0], 'name': 'name', 'start_event': { 'id': id_list[1], 'name': 'start', 'type': 'EmptyStartEvent', 'incoming': None, 'outgoing': id_list[2] }, 'end_event': { 'id': id_list[53], 'name': 'end', 'type': 'EmptyEndEvent', 'incoming': id_list[52], 'outgoing': None }, 'activities': { }, 'flows': { # 存放该 Pipeline 中所有的线 }, 'gateways': { # 这里存放着网关的详细信息 }, 'data': { 'inputs': { }, 'outputs': { }, } } for i in xrange(2, 51, 2): pipe1['flows'][id_list[i]] = { 'id': id_list[i], 'source': id_list[i - 1], 'target': id_list[i + 1] } pipe1['activities'][id_list[i + 1]] = { 'id': id_list[i + 1], 'type': 'ServiceActivity', 'name': 'first_task', 'incoming': id_list[i], 'outgoing': id_list[i + 2], 'component': { 'code': 'demo', 'inputs': { 'input_test': { 'type': 'plain', 'value': '2', }, 'radio_test': { 'type': 'plain', 'value': '1', }, }, } } pipe1['flows'][id_list[52]] = { 'id': id_list[52], 'source': id_list[52 - 1], 'target': id_list[52 + 1] } parser_obj = PipelineParser(pipe1) run_pipeline(parser_obj.parser())
def test_run_serial_pipeline(): pipeline = PIPELINE_DATA parser_obj = PipelineParser(pipeline) run_pipeline(parser_obj.parser())
def test_conditional_parallel_parser(self): parser_obj = PipelineParser(CONDITIONAL_PARALLEL) self.assertIsInstance(parser_obj.parse(), Pipeline)
PIPELINE_DATA, PIPELINE_WITH_SUB_PROCESS, CONDITIONAL_PARALLEL, ) from pipeline.component_framework.component import Component from pipeline.core.flow.activity import Service from pipeline.service import task_service class TestService(Service): def execute(self, data, parent_data): print(data, parent_data) return True def outputs_format(self): return [] class TestComponent(Component): name = 'test' code = 'test' bound_service = TestService form = 'test.js' if __name__ == "__main__": parser_obj = PipelineParser(PIPELINE_DATA) pipeline = parser_obj.parser() act_result = task_service.run_pipeline(pipeline) print(pipeline)