def _save_status(self, action_instance, session, post_data, allow_save=False): if 'status' in post_data: status = self.get_status_by_name(post_data['status'], session) if action_instance.callback_required and status.type == StatusTypes.SUCCESS and not allow_save: # Allow_save comes from callback_method. return self._wait_for_parallel_calculations(action_instance) pipeline_instance = session.query(PipelineInstance).options( joinedload(PipelineInstance.stage_instances).joinedload( StageInstance.workflow_instances).joinedload( WorkflowInstance.action_instances)).options( joinedload(PipelineInstance.parameters)).get( action_instance.pipeline_instance_id) workflow_engine = InstanceWorkflowEngine(StatusDal(session), pipeline_instance) workflow_engine.complete_an_action(action_instance.id, status.id) for instance in workflow_engine.instances_to_add: session.add(instance) session.commit() self.event_service.trigger_possible_event(pipeline_instance, action_instance, session)
def test_complex_reset_action_complete_stage_should_activate_proper_actions( self): pipeline_instance = self._build_pipeline_instance( ['1:1', '7:1-1-1-1,1,4,1-1-1-1']) workflow_engine = InstanceWorkflowEngine(self._get_mocked_dal(), pipeline_instance) workflow_engine.reset_pipeline() first_stage = pipeline_instance.stage_instances[0] second_stage = pipeline_instance.stage_instances[1] workflow_engine.complete_an_action(1, StatusConstants.SUCCESS) self.assertEquals(StatusConstants.SUCCESS, first_stage.status_id) self.assertEquals(StatusConstants.SUCCESS, first_stage.workflow_instances[0].status_id) self.assertEquals( StatusConstants.SUCCESS, first_stage.workflow_instances[0].action_instances[0].status_id) self.assertEquals(StatusConstants.INPROGRESS, second_stage.status_id) for workflow_instance in second_stage.workflow_instances: self.assertEquals(StatusConstants.INPROGRESS, workflow_instance.status_id) for action_instance in workflow_instance.action_instances: if action_instance.order == 0: self.assertEquals(StatusConstants.READY, action_instance.status_id) else: self.assertEquals(StatusConstants.NEW, action_instance.status_id)
def cancel_action_instance(self, action_instance_id): for session in get_db_session(): action_instance = self.get_action_instance_by_id( action_instance_id, session) if action_instance: serialized = action_instance.serialize() instance_workflow_engine = InstanceWorkflowEngine( StatusDal(session), action_instance.pipeline_instance) instance_workflow_engine.complete_an_action( action_instance_id, StatusConstants.CANCELED) self.queue_constants.cancel_worker(serialized) session.commit() else: raise InvalidObjectException("Action Instance not found", 404) return {"message": "Action Instance has been canceled."}
def test_complete_an_action_instance_sets_dates_and_status(self): pipeline_instance = self._build_pipeline_instance(['1:1']) workflow_engine = InstanceWorkflowEngine(self._get_mocked_dal(), pipeline_instance) action_instance = workflow_engine.get_action_instance_by_id(1) workflow_engine.complete_an_action(action_instance.id, StatusConstants.CANCELED) self.assertEqual(StatusConstants.CANCELED, action_instance.status_id) self.assertEqual(StatusConstants.CANCELED, pipeline_instance.status_id) self.assertEqual(StatusConstants.CANCELED, pipeline_instance.stage_instances[0].status_id) self.assertEqual( StatusConstants.CANCELED, pipeline_instance.stage_instances[0]. workflow_instances[0].status_id)
def test_complete_an_action_instance_starts_next(self): pipeline_instance = self._build_pipeline_instance(['1:2']) pipeline_instance.status_id = StatusConstants.INPROGRESS workflow_engine = InstanceWorkflowEngine(self._get_mocked_dal(), pipeline_instance) action_instance = workflow_engine.get_action_instance_by_id(2) workflow_engine.complete_an_action(1, StatusConstants.SUCCESS) self._print_pipeline_instance(pipeline_instance) self.assertEqual(StatusConstants.READY, action_instance.status_id) self.assertEqual(StatusConstants.INPROGRESS, pipeline_instance.status_id) self.assertEqual( StatusConstants.SUCCESS, pipeline_instance.stage_instances[0]. workflow_instances[0].action_instances[0].status_id) self.assertEqual( StatusConstants.READY, pipeline_instance.stage_instances[0]. workflow_instances[0].action_instances[1].status_id)