コード例 #1
0
 def test_update_scheduler(self):
     task = ScheduledTask(name='test', task_trigger=self.date_trigger)
     update = {'task_trigger': {'type': 'interval', 'args': {'hours': 1, 'weeks': 4}}}
     task.update(update)
     self.assertEqual(task.trigger_type, 'interval')
     self.assertDictEqual(json.loads(task.trigger_args), {'hours': 1, 'weeks': 4})
     self.assertSchedulerWorkflowsRunningEqual(workflows=None)
コード例 #2
0
 def test_update_scheduler_invalid_scheduler(self):
     task = ScheduledTask(name='test', task_trigger=self.date_trigger)
     update = {'name': 'renamed', 'task_trigger': {'type': 'interval', 'args': {'invalid': 1, 'weeks': 4}}}
     with self.assertRaises(InvalidTriggerArgs):
         task.update(update)
     self.assertEqual(task.name, 'test')
     self.assertSchedulerWorkflowsRunningEqual(workflows=None)
コード例 #3
0
 def test_stop_from_running_with_workflows(self):
     workflows = ['a', 'b', 'c', 'd']
     self.patch_controller_workflows(workflows)
     task = ScheduledTask(name='test', task_trigger=self.date_trigger, workflows=['b', 'c', 'd'])
     task.stop()
     self.assertEqual(task.status, 'stopped')
     self.assertSchedulerWorkflowsRunningEqual(workflows=None)
コード例 #4
0
 def test_update_workflows_none_existing_running(self):
     workflows = ['a', 'b', 'c', 'd']
     self.patch_controller_workflows(workflows)
     task = ScheduledTask(name='test', task_trigger=self.date_trigger, status='running')
     update = {'workflows': ['a', 'b', 'c']}
     task.update(update)
     self.assertListEqual([workflow.uid for workflow in task.workflows], ['a', 'b', 'c'])
     self.assertSchedulerWorkflowsRunningEqual(['a', 'b', 'c'])
コード例 #5
0
 def test_update_workflows_with_existing_workflows_running_add_and_remove(self):
     workflows = ['a', 'b', 'c', 'd']
     self.patch_controller_workflows(workflows)
     task = ScheduledTask(name='test', task_trigger=self.date_trigger, workflows=['b', 'c', 'd'], status='running')
     update = {'workflows': ['a', 'b']}
     task.update(update)
     self.assertSetEqual({workflow.uid for workflow in task.workflows}, {'a', 'b'})
     self.assertSchedulerWorkflowsRunningEqual(['a', 'b'])
コード例 #6
0
ファイル: scheduler.py プロジェクト: dvbnrg/WALKOFF
 def __func():
     data = request.get_json()
     task = ScheduledTask.query.filter_by(name=data['name']).first()
     if task is None:
         try:
             task = ScheduledTask(**data)
         except InvalidTriggerArgs:
             return {'error': 'invalid scheduler arguments'}, 400
         else:
             db.session.add(task)
             db.session.commit()
             return task.as_json(), OBJECT_CREATED
     else:
         return {'error': 'Could not create object. Object with given name already exists'}, OBJECT_EXISTS_ERROR
コード例 #7
0
 def test_read_all_scheduled_tasks_with_tasks(self):
     tasks = [ScheduledTask(name='test-{}'.format(i)) for i in range(4)]
     db.session.add_all(tasks)
     expected = [task.as_json() for task in ScheduledTask.query.all()]
     response = self.get_with_status_check('/api/scheduledtasks',
                                           headers=self.headers)
     self.assertListEqual(response, expected)
コード例 #8
0
 def test_init_with_status_with_trigger_without_workflows(self):
     workflows = ['uid1', 'uid2', 'uid3', 'uid4']
     self.patch_controller_workflows(workflows)
     task = ScheduledTask(name='test', task_trigger=self.date_trigger, status='running')
     self.assertStructureIsCorrect(task, 'test', trigger_type='date',
                                   trigger_args={'run_date': '2017-01-25 10:00:00'},
                                   status='running')
コード例 #9
0
 def test_as_json_with_scheduler(self):
     task = ScheduledTask(name='test', task_trigger=self.date_trigger)
     expected = {'id': None,
                 'name': 'test',
                 'description': '',
                 'status': 'running',
                 'workflows': set(),
                 'task_trigger': self.date_trigger}
     self.assertJsonIsCorrect(task, expected)
コード例 #10
0
 def test_as_json_running(self):
     task = ScheduledTask(name='test', status='stopped')
     expected = {'id': None,
                 'name': 'test',
                 'description': '',
                 'status': 'stopped',
                 'workflows': set(),
                 'task_trigger': {'type': 'unspecified',
                                  'args': {}}}
     self.assertJsonIsCorrect(task, expected)
コード例 #11
0
 def test_as_json_with_workflows_with_duplicates(self):
     task = ScheduledTask(name='test', workflows=['b', 'c', 'd', 'd', 'c', 'b'])
     expected = {'id': None,
                 'name': 'test',
                 'description': '',
                 'status': 'running',
                 'workflows': {'b', 'c', 'd'},
                 'task_trigger': {'type': 'unspecified',
                                  'args': {}}}
     self.assertJsonIsCorrect(task, expected)
コード例 #12
0
 def test_init_stopped(self):
     task = ScheduledTask(name='test', status='stopped')
     self.assertStructureIsCorrect(task, 'test', status='stopped')
コード例 #13
0
 def test_init_with_invalid_trigger(self):
     trigger = {'type': 'date', 'args': {'run_date': '2017-100-25 10:00:00'}}
     with self.assertRaises(InvalidTriggerArgs):
         ScheduledTask(name='test', task_trigger=trigger)
コード例 #14
0
 def test_init_with_trigger(self):
     task = ScheduledTask(name='test', task_trigger=self.date_trigger)
     self.assertStructureIsCorrect(task, 'test', trigger_type='date',
                                   trigger_args={'run_date': '2017-01-25 10:00:00'})
コード例 #15
0
 def test_init_with_workflows(self):
     task = ScheduledTask(name='test', workflows=['uid1', 'uid2', 'uid3', 'uid4'])
     self.assertStructureIsCorrect(task, 'test', workflows={'uid1', 'uid2', 'uid3', 'uid4'})
コード例 #16
0
 def test_init_with_invalid_status(self):
     task = ScheduledTask(name='test', status='invalid')
     self.assertStructureIsCorrect(task, 'test')
コード例 #17
0
 def test_init_with_description(self):
     task = ScheduledTask(name='test', description='desc')
     self.assertStructureIsCorrect(task, 'test', description='desc')
コード例 #18
0
 def test_init_default(self):
     task = ScheduledTask(name='test')
     self.assertStructureIsCorrect(task, 'test')
コード例 #19
0
 def test_update_workflows_none_existing_stopped(self):
     task = ScheduledTask(name='test', status='stopped')
     update = {'workflows': ['a', 'b', 'c']}
     task.update(update)
     self.assertListEqual([workflow.uid for workflow in task.workflows], ['a', 'b', 'c'])
     self.assertSchedulerWorkflowsRunningEqual(workflows=None)
コード例 #20
0
 def test_start_from_running(self):
     task = ScheduledTask(name='test', status='running')
     task.start()
     self.assertEqual(task.status, 'running')
     self.assertSchedulerWorkflowsRunningEqual(workflows=None)
コード例 #21
0
 def test_init_with_status_trigger_unspecified(self):
     workflows = ['uid1', 'uid2', 'uid3', 'uid4']
     self.patch_controller_workflows(workflows)
     task = ScheduledTask(name='test', status='running', workflows=['uid1', 'uid2', 'uid3', 'uid4'])
     self.assertStructureIsCorrect(task, 'test', status='running', workflows=set(workflows))
コード例 #22
0
 def test_update_name_desc_only(self):
     task = ScheduledTask(name='test')
     update = {'name': 'updated_name', 'description': 'desc'}
     task.update(update)
     self.assertEqual(task.name, 'updated_name')
     self.assertEqual(task.description, 'desc')
コード例 #23
0
 def test_stop_from_running_no_workflows(self):
     task = ScheduledTask(name='test', status='running')
     task.stop()
     self.assertEqual(task.status, 'stopped')
     self.assertSchedulerWorkflowsRunningEqual(workflows=None)
コード例 #24
0
 def test_start_from_stopped_unspecified_trigger(self):
     task = ScheduledTask(name='test')
     task.start()
     self.assertEqual(task.status, 'running')
     self.assertSchedulerWorkflowsRunningEqual(workflows=None)
コード例 #25
0
 def test_stop_from_stopped(self):
     task = ScheduledTask(name='test')
     task.stop()
     self.assertEqual(task.status, 'stopped')
コード例 #26
0
 def test_update_workflows_with_existing_workflows_stopped(self):
     task = ScheduledTask(name='test', workflows=['b', 'c', 'd'])
     update = {'workflows': ['a', 'b', 'c']}
     task.update(update)
     self.assertSetEqual({workflow.uid for workflow in task.workflows}, {'a', 'b', 'c'})
     self.assertSchedulerWorkflowsRunningEqual(workflows=None)