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 get_workflow_status(self, workflow_execution_id, status):
     workflow_id = uuid4()
     workflow_status = WorkflowStatus(workflow_execution_id, workflow_id, 'workflow1')
     action_execution_id = uuid4()
     action_id = uuid4()
     self.app.running_context.execution_db.session.add(workflow_status)
     action_status = ActionStatus(action_execution_id, action_id, 'my action', 'the_app', 'the_action')
     self.app.running_context.execution_db.session.add(action_status)
     workflow_status.add_action_status(action_status)
     expected = {
         'execution_id': str(workflow_execution_id),
         'workflow_id': str(workflow_id),
         'name': 'workflow1',
         'status': status.name,
         'current_action': action_status.as_json(summary=True)}
     return expected, workflow_status
Exemplo n.º 3
0
 def get_workflow_status(self, workflow_execution_id, status):
     workflow_id = uuid4()
     workflow_status = WorkflowStatus(workflow_execution_id, workflow_id, 'workflow1')
     action_execution_id = uuid4()
     action_id = uuid4()
     self.app.running_context.execution_db.session.add(workflow_status)
     action_status = ActionStatus(action_execution_id, action_id, 'my action', 'the_app', 'the_action')
     self.app.running_context.execution_db.session.add(action_status)
     workflow_status.add_action_status(action_status)
     expected = {
         'execution_id': str(workflow_execution_id),
         'workflow_id': str(workflow_id),
         'name': 'workflow1',
         'status': status.name,
         'current_action': action_status.as_json(summary=True)}
     return expected, workflow_status
Exemplo n.º 4
0
    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)

        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(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 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)
Exemplo n.º 6
0
def __action_start_callback(sender, **kwargs):
    workflow_execution_id = kwargs['data']['workflow']['execution_id']
    current_app.running_context.execution_db.session.expire_all()
    action_status = current_app.running_context.execution_db.session.query(ActionStatus).filter_by(
        execution_id=sender['execution_id']).first()
    if action_status:
        action_status.status = ActionStatusEnum.executing
    else:
        workflow_status = current_app.running_context.execution_db.session.query(WorkflowStatus).filter_by(
            execution_id=workflow_execution_id).first()
        arguments = sender['arguments'] if 'arguments' in sender else []
        action_status = ActionStatus(sender['execution_id'], sender['id'], sender['name'], sender['app_name'],
                                     sender['action_name'], json.dumps(arguments))
        workflow_status.add_action_status(action_status)
        current_app.running_context.execution_db.session.add(action_status)

    current_app.running_context.execution_db.session.commit()
 def make_generic_action_statuses(number):
     return [
         ActionStatus(uuid4(), uuid4(), 'app', 'action', 'name')
         for _ in range(number)
     ]