def test_read_all_workflow_status_no_action(self):
        exec_id = uuid4()
        wf_id = uuid4()
        workflow_status = WorkflowStatus(exec_id, wf_id, 'test')
        workflow_status.running()

        self.app.running_context.execution_db.session.add(workflow_status)
        self.app.running_context.execution_db.session.commit()

        response = self.get_with_status_check('/api/workflowqueue',
                                              headers=self.headers)

        self.assertEqual(len(response), 1)
        response = response[0]

        self.assertIn('started_at', response)
        response.pop('started_at')

        expected = {
            'execution_id': str(exec_id),
            'workflow_id': str(wf_id),
            'name': 'test',
            'status': 'running'
        }

        self.assertDictEqual(response, expected)
    def test_execute_workflow_pause_resume(self):
        result = {'paused': False, 'resumed': False}
        wf_exec_id = uuid4()
        wf_id = uuid4()

        @WalkoffEvent.WorkflowPaused.connect
        def workflow_paused_listener(sender, **kwargs):
            result['paused'] = True

            wf_status = self.app.running_context.execution_db.session.query(
                WorkflowStatus).filter_by(
                    execution_id=str(wf_exec_id)).first()
            self.assertIsNotNone(wf_status)

            self.act_on_workflow(str(wf_exec_id), 'resume')

        @WalkoffEvent.WorkflowResumed.connect
        def workflow_resumed_listener(sender, **kwargs):
            result['resumed'] = True

        workflow_status = WorkflowStatus(wf_exec_id, wf_id, 'test')
        workflow_status.running()
        self.app.running_context.execution_db.session.add(workflow_status)
        self.app.running_context.execution_db.session.commit()

        self.act_on_workflow(str(wf_exec_id), 'pause')

        self.assertTrue(result['paused'])
        self.assertTrue(result['resumed'])
    def test_clear_workflow_status_by_days(self):
        for i in range(10):
            wf_exec_id = uuid4()
            wf_id = uuid4()
            workflow_status = WorkflowStatus(wf_exec_id, wf_id, 'test')
            workflow_status.running()
            workflow_status.started_at = datetime.datetime.today(
            ) - datetime.timedelta(days=40)

            action_exec_id = uuid4()
            action_id = uuid4()
            action_status = ActionStatus(action_exec_id, action_id, 'name',
                                         'test_app', 'test_action')
            workflow_status._action_statuses.append(action_status)

            workflow_status.completed()
            workflow_status.completed_at = datetime.datetime.today(
            ) - datetime.timedelta(days=40)

            self.app.running_context.execution_db.session.add(workflow_status)
            self.app.running_context.execution_db.session.commit()

        self.delete_with_status_check('/api/workflowqueue/cleardb?days=30',
                                      headers=self.headers,
                                      status_code=NO_CONTENT)

        wf_stats = self.app.running_context.execution_db.session.query(
            WorkflowStatus).all()
        self.assertEqual(len(wf_stats), 0)
        action_stats = self.app.running_context.execution_db.session.query(
            ActionStatus).all()
        self.assertEqual(len(action_stats), 0)
    def test_read_workflow_status(self):
        wf_exec_id = uuid4()
        wf_id = uuid4()
        workflow_status = WorkflowStatus(wf_exec_id, wf_id, 'test')
        workflow_status.running()

        action_exec_id = uuid4()
        action_id = uuid4()
        action_status = ActionStatus(action_exec_id, action_id, 'name',
                                     'test_app', 'test_action')
        workflow_status._action_statuses.append(action_status)

        self.app.running_context.execution_db.session.add(workflow_status)
        self.app.running_context.execution_db.session.commit()

        response = self.get_with_status_check('/api/workflowqueue/{}'.format(
            str(wf_exec_id)),
                                              headers=self.headers)

        self.assertIn('started_at', response)
        response.pop('started_at')

        self.assertIn('action_statuses', response)
        self.assertIn('started_at', response['action_statuses'][-1])
        response['action_statuses'][-1].pop('started_at')

        expected = {
            'execution_id':
            str(wf_exec_id),
            'workflow_id':
            str(wf_id),
            'name':
            'test',
            'status':
            'running',
            'action_statuses': [{
                'execution_id': str(action_exec_id),
                'action_id': str(action_id),
                'name': 'name',
                'app_name': 'test_app',
                'action_name': 'test_action',
                'status': 'executing',
                'arguments': []
            }]
        }

        self.assertDictEqual(response, expected)
    def test_workflowqueue_pagination(self):
        for i in range(40):
            workflow_status = WorkflowStatus(uuid4(), uuid4(), 'test')
            workflow_status.running()
            self.app.running_context.execution_db.session.add(workflow_status)
            self.app.running_context.execution_db.session.commit()

        response = self.get_with_status_check('/api/workflowqueue',
                                              headers=self.headers)
        self.assertEqual(len(response), 20)

        response = self.get_with_status_check('/api/workflowqueue?page=2',
                                              headers=self.headers)
        self.assertEqual(len(response), 20)

        response = self.get_with_status_check('/api/workflowqueue?page=3',
                                              headers=self.headers)
        self.assertEqual(len(response), 0)
Exemple #6
0
def __workflow_pending(sender, **kwargs):
    current_app.running_context.execution_db.session.expire_all()
    workflow_status = current_app.running_context.execution_db.session.query(WorkflowStatus).filter_by(
        execution_id=sender['execution_id']).first()
    if workflow_status:
        workflow_status.status = WorkflowStatusEnum.pending
    else:
        workflow_status = WorkflowStatus(sender['execution_id'], sender['id'], sender['name'])
        current_app.running_context.execution_db.session.add(workflow_status)
    current_app.running_context.execution_db.session.commit()
Exemple #7
0
def __workflow_pending(sender, **kwargs):
    current_app.running_context.execution_db.session.expire_all()
    workflow_status = current_app.running_context.execution_db.session.query(WorkflowStatus).filter_by(
        execution_id=str(sender['execution_id'])).first()
    if workflow_status:
        workflow_status.status = WorkflowStatusEnum.pending
    else:
        user = kwargs['data']['user'] if ('data' in kwargs and 'user' in kwargs['data']) else None
        workflow_status = WorkflowStatus(str(sender['execution_id']), sender['id'], sender['name'], user=user)
        current_app.running_context.execution_db.session.add(workflow_status)
    current_app.running_context.execution_db.session.commit()
def __workflow_pending(sender, **kwargs):
    executiondb.execution_db.session.expire_all()
    workflow_status = executiondb.execution_db.session.query(
        WorkflowStatus).filter_by(execution_id=sender['execution_id']).first()
    if workflow_status:
        workflow_status.status = WorkflowStatusEnum.pending
    else:
        workflow_status = WorkflowStatus(sender['execution_id'], sender['id'],
                                         sender['name'])
        executiondb.execution_db.session.add(workflow_status)
    executiondb.execution_db.session.commit()
    def test_read_all_workflow_status_with_action(self):
        wf_exec_id = uuid4()
        wf_id = uuid4()
        workflow_status = WorkflowStatus(wf_exec_id, wf_id, 'test')
        workflow_status.running()

        action_exec_id = uuid4()
        action_id = uuid4()
        action_status = ActionStatus(action_exec_id, action_id, 'name',
                                     'test_app', 'test_action')
        workflow_status._action_statuses.append(action_status)

        executiondb.execution_db.session.add(workflow_status)
        executiondb.execution_db.session.commit()

        response = self.get_with_status_check('/api/workflowqueue',
                                              headers=self.headers)

        self.assertEqual(len(response), 1)
        response = response[0]

        self.assertIn('started_at', response)
        response.pop('started_at')
        expected = {
            'execution_id': str(wf_exec_id),
            'workflow_id': str(wf_id),
            'name': 'test',
            'status': 'running',
            'current_action': {
                'execution_id': str(action_exec_id),
                'action_id': str(action_id),
                'action_name': 'test_action',
                'app_name': 'test_app',
                'name': 'name'
            }
        }
        self.assertDictEqual(response, expected)
 def make_generic_workflow_status():
     return WorkflowStatus(uuid4(), uuid4(), 'wf1')