Beispiel #1
0
 def _create_execution(cls, workbook_name, task_name, context):
     return db_api.execution_create(workbook_name, {
         "workbook_name": workbook_name,
         "task": task_name,
         "state": states.RUNNING,
         "context": context
     })
Beispiel #2
0
    def test_handle_task(self):
        # Create a new workbook.
        workbook = db_api.workbook_create(SAMPLE_WORKBOOK)
        self.assertIsInstance(workbook, dict)

        # Create a new execution.
        execution = db_api.execution_create(SAMPLE_EXECUTION['workbook_name'],
                                            SAMPLE_EXECUTION)
        self.assertIsInstance(execution, dict)

        # Create a new task.
        SAMPLE_TASK['execution_id'] = execution['id']
        task = db_api.task_create(SAMPLE_TASK['workbook_name'],
                                  SAMPLE_TASK['execution_id'],
                                  SAMPLE_TASK)
        self.assertIsInstance(task, dict)
        self.assertIn('id', task)

        # Send the task request to the Executor.
        ex_client = executor.ExecutorClient(self.transport)
        ex_client.handle_task(SAMPLE_CONTEXT, task=task)

        # Check task execution state.
        db_task = db_api.task_get(task['workbook_name'],
                                  task['execution_id'],
                                  task['id'])
        self.assertEqual(db_task['state'], states.SUCCESS)
    def test_handle_task(self):
        # Create a new workbook.
        workbook = db_api.workbook_create(SAMPLE_WORKBOOK)
        self.assertIsInstance(workbook, dict)

        # Create a new execution.
        execution = db_api.execution_create(SAMPLE_EXECUTION['workbook_name'],
                                            SAMPLE_EXECUTION)
        self.assertIsInstance(execution, dict)

        # Create a new task.
        SAMPLE_TASK['execution_id'] = execution['id']
        task = db_api.task_create(SAMPLE_TASK['workbook_name'],
                                  SAMPLE_TASK['execution_id'],
                                  SAMPLE_TASK)
        self.assertIsInstance(task, dict)
        self.assertIn('id', task)

        # Send the task request to the Executor.
        ex_client = executor.ExecutorClient(self.transport)
        ex_client.handle_task(SAMPLE_CONTEXT, task=task)

        # Check task execution state.
        db_task = db_api.task_get(task['workbook_name'],
                                  task['execution_id'],
                                  task['id'])
        self.assertEqual(db_task['state'], states.SUCCESS)
Beispiel #4
0
 def _create_execution(cls, workbook_name, task_name, context):
     return db_api.execution_create(
         workbook_name, {
             "workbook_name": workbook_name,
             "task": task_name,
             "state": states.RUNNING,
             "context": context
         })
Beispiel #5
0
 def setUp(self):
     super(TestExecutor, self).setUp()
     # Create a new workbook.
     self.workbook = db_api.workbook_create(SAMPLE_WORKBOOK)
     # Create a new execution.
     self.execution = db_api.execution_create(
         SAMPLE_EXECUTION['workbook_name'], SAMPLE_EXECUTION)
     # Create a new task.
     SAMPLE_TASK['execution_id'] = self.execution['id']
     self.task = db_api.task_create(
         SAMPLE_TASK['execution_id'], SAMPLE_TASK)
Beispiel #6
0
    def test_handle_task(self):
        # Mock the RestAction
        mock_rest_action = self.mock_action_run()

        # Create a new workbook.
        workbook = db_api.workbook_create(SAMPLE_WORKBOOK)
        self.assertIsInstance(workbook, dict)

        # Create a new execution.
        execution = db_api.execution_create(SAMPLE_EXECUTION['workbook_name'],
                                            SAMPLE_EXECUTION)
        self.assertIsInstance(execution, dict)

        # Create a new task.
        SAMPLE_TASK['execution_id'] = execution['id']
        task = db_api.task_create(SAMPLE_TASK['workbook_name'],
                                  SAMPLE_TASK['execution_id'],
                                  SAMPLE_TASK)
        self.assertIsInstance(task, dict)
        self.assertIn('id', task)

        # Send the task request to the Executor.
        transport = self.server.transport
        ex_client = client.ExecutorClient(transport)
        ex_client.handle_task(SAMPLE_CONTEXT, task=task)

        # Check task execution state. There is no timeout mechanism in
        # unittest. There is an example to add a custom timeout decorator that
        # can wrap this test function in another process and then manage the
        # process time. However, it seems more straightforward to keep the
        # loop finite.
        for i in range(0, 50):
            db_task = db_api.task_get(task['workbook_name'],
                                      task['execution_id'],
                                      task['id'])
            # Ensure the request reached the executor and the action has ran.
            if db_task['state'] != states.IDLE:
                mock_rest_action.assert_called_once_with()
                self.assertIn(db_task['state'],
                              [states.RUNNING, states.SUCCESS, states.ERROR])
                return
            time.sleep(0.1)

        # Task is not being processed. Throw an exception here.
        raise Exception('Timed out waiting for task to be processed.')