def handle(self, *args, **kwargs): additional_arguments = None if kwargs['force']: additional_arguments = { 'force_update': True } run_task(UpdateRepositoriesTask, additional_arguments)
def test_run_job_complex_1(self, *args, **kwargs): """ Tests running a job consisting of complex dependencies. """ T0 = self.create_task_class(('A', 'B'), (), ('A',)) T1 = self.create_task_class(('D', 'D1'), ('A',), ('D')) T2 = self.create_task_class(('C',), ('A',), ('C',)) self.create_task_class(('E',), ('B',), ('E',)) # T3 self.create_task_class((), ('B',), ()) # T4 T5 = self.create_task_class(('evt-5',), ('D',), ('evt-5',)) T6 = self.create_task_class(('evt-6',), ('C'), ('evt-6',)) T7 = self.create_task_class((), ('D1', 'A'), ()) T8 = self.create_task_class((), ('evt-5', 'evt-6', 'E'), ()) run_task(T0) # Make sure the tasks which didn't have the appropriate events raised # during execution were not executed. These are tasks T3 and T4 in this # instance. self.assert_executed_tasks_equal([T0, T1, T2, T5, T6, T7, T8]) # Check execution order. self.assert_task_dependency_preserved(T0, [T1, T2, T7]) # Even though task T1 does not emit the event D1, it still needs to # execute before task T7. self.assert_task_dependency_preserved(T1, [T5, T7]) self.assert_task_dependency_preserved(T2, [T6]) self.assert_task_dependency_preserved(T5, [T8]) self.assert_task_dependency_preserved(T6, [T8])
def test_run_job_no_dependency(self, *args, **kwargs): """ Tests running a job consisting of no dependencies. """ self.create_task_class(('a',), (), ('a',)) B = self.create_task_class(('b',), (), ('b',)) run_task(B) self.assert_executed_tasks_equal([B])
def test_run_job_with_fail_task(self, *args, **kwargs): """ Tests that running a job where one task fails works as expected. """ fail_task = self.create_task_class(('fail',), (), ('fail'), fail=True) run_task(fail_task) # The job has gracefully exited without raising an exception. self.assert_executed_tasks_equal([fail_task])
def test_run_job_simple(self, *args, **kwargs): """ Tests running a job consisting of a simple dependency. """ A = self.create_task_class(('a',), (), ('a',)) B = self.create_task_class((), ('a',), ()) run_task(A) self.assert_executed_tasks_equal([A, B]) self.assert_task_dependency_preserved(A, [B])
def test_run_job_no_events_emitted(self, *args, **kwargs): """ Tests running a job consisting of a simple dependency, but the event is not emitted during execution. """ A = self.create_task_class(('a',), (), ()) self.create_task_class((), ('a',), ()) run_task(A) self.assert_executed_tasks_equal([A])
def test_run_job_by_task_name(self, *args, **kwargs): """ Tests that the :func:`distro_tracker.core.tasks.run_task` function correctly runs a task when given its name, not a task class object. """ A = self.create_task_class(('a',), (), ('a',)) B = self.create_task_class((), ('a',), ()) run_task(A.task_name()) self.assert_executed_tasks_equal([A, B]) self.assert_task_dependency_preserved(A, [B])
def test_run_job_with_fail_task_dependency(self, *args, **kwargs): """ Tests that even though a task has failed, any events it raised while running affect the rest of the tasks. """ root_task = self.create_task_class(('A',), (), ('A',)) fail_task = self.create_task_class(('fail',), ('A',), ('fail',), True) depends_on_fail = self.create_task_class((), ('fail',), ()) do_run = self.create_task_class((), ('A',), ()) run_task(root_task) self.assert_executed_tasks_equal( [root_task, fail_task, depends_on_fail, do_run] )
def handle(self, *args, **kwargs): verbose = int(kwargs.get("verbosity", 1)) > 0 additional_arguments = None if kwargs["force"]: additional_arguments = {"force_update": True} for task_name in args: if isinstance(task_name, bytes): task_name = task_name.decode("utf-8") logger.info("Starting task %s (from ./manage.py tracker_run_task)", task_name) try: run_task(task_name, additional_arguments) except: logger.exception("Task %s failed:", task_name) if verbose: self.stdout.write("Task {} failed:\n".format(task_name)) traceback.print_exc(file=self.stdout)
def test_run_job_complex_4(self, *args, **kwargs): """ Tests running a job consisting of complex dependencies when the initial task is not the task which has 0 dependencies in the full tasks DAG. """ self.create_task_class(('A', 'B'), (), ('B',)) # T0 T1 = self.create_task_class(('D', 'D1'), ('A',), ('D')) self.create_task_class(('C',), ('A',), ('C',)) # T2 self.create_task_class(('E',), ('B',), ('E',)) # T3 self.create_task_class((), ('B',), ()) # T4 T5 = self.create_task_class(('evt-5',), ('D',), ('evt-5',)) self.create_task_class(('evt-6',), ('C'), ('evt-6',)) # T6 self.create_task_class((), ('D1', 'A'), ()) # T7 T8 = self.create_task_class((), ('evt-5', 'evt-6', 'E'), ()) run_task(T1) self.assert_executed_tasks_equal([T1, T5, T8])
def handle(self, *args, **kwargs): verbose = int(kwargs.get('verbosity', 1)) > 0 additional_arguments = None if kwargs['force']: additional_arguments = { 'force_update': True } for task_name in args: task_name = task_name.decode('utf-8') logger.info("Starting task %s (from ./manage.py tracker_run_task)", task_name) try: run_task(task_name, additional_arguments) except: logger.exception("Task %s failed:", task_name) if verbose: self.stdout.write('Task {} failed:\n'.format(task_name)) traceback.print_exc(file=self.stdout)
def test_run_job_complex_3(self, *args, **kwargs): """ Tests running a job consisting of complex dependencies. """ T0 = self.create_task_class(('A', 'B', 'B1'), (), ('B', 'B1')) self.create_task_class(('D', 'D1'), ('A',), ('D')) # T1 self.create_task_class(('C',), ('A',), ('C',)) # T2 T3 = self.create_task_class(('E',), ('B',), ('E',)) T4 = self.create_task_class((), ('B',), ()) self.create_task_class(('evt-5',), ('D',), ('evt-5',)) # T5 self.create_task_class(('evt-6',), ('C'), ('evt-6',)) # T6 T7 = self.create_task_class((), ('D1', 'A', 'B1'), ()) T8 = self.create_task_class((), ('evt-5', 'evt-6', 'E'), ()) run_task(T0) self.assert_executed_tasks_equal([T0, T3, T4, T7, T8]) self.assert_task_dependency_preserved(T0, [T3, T4, T7]) self.assert_task_dependency_preserved(T3, [T8])
def handle(self, *args, **kwargs): params = {} if kwargs['force_update']: params['force_update'] = True if kwargs['fake_update']: params['fake_update'] = True for task_name in kwargs['tasks']: if isinstance(task_name, bytes): task_name = task_name.decode('utf-8') logger.info("./manage.py tracker_run_task %s", task_name) if not run_task(task_name, **params): self.stderr.write('Task {} failed to run.\n'.format(task_name))
def test_run_job_complex_5(self, *args, **kwargs): """ Tests running a job consisting of complex dependencies when the initial task is not the task which has 0 dependencies in the full tasks DAG. """ T0 = self.create_task_class(('A', 'B'), (), ('B',)) T1 = self.create_task_class(('D', 'D1'), ('A',), ('D', 'D1')) T2 = self.create_task_class(('C',), ('A',), ('C',)) T3 = self.create_task_class(('E',), ('B',), ('E',)) T4 = self.create_task_class((), ('B',), ()) T5 = self.create_task_class(('evt-5',), ('D',), ('evt-5',)) T6 = self.create_task_class(('evt-6',), ('C'), ('evt-6',)) T7 = self.create_task_class((), ('D1', 'A'), ()) T8 = self.create_task_class((), ('evt-5', 'evt-6', 'E'), ()) run_task(T1) self.assert_executed_tasks_equal([T1, T5, T8, T7]) self.assert_task_dependency_preserved(T1, [T7, T5]) self.assert_task_dependency_preserved(T5, [T8])
def test_run_job_complex_2(self, *args, **kwargs): """ Tests running a job consisting of complex dependencies. """ T0 = self.create_task_class(('A', 'B'), (), ('B',)) self.create_task_class(('D', 'D1'), ('A',), ('D')) # T1 self.create_task_class(('C',), ('A',), ('C',)) # T2 T3 = self.create_task_class(('E',), ('B',), ('E',)) T4 = self.create_task_class((), ('B',), ()) self.create_task_class(('evt-5',), ('D',), ('evt-5',)) # T5 self.create_task_class(('evt-6',), ('C'), ('evt-6',)) # T6 self.create_task_class((), ('D1', 'A'), ()) # T7 T8 = self.create_task_class((), ('evt-5', 'evt-6', 'E'), ()) run_task(T0) # In this test case, unlike test_run_job_complex_1, T0 emits event B so # no tasks depending on event A need to run. self.assert_executed_tasks_equal([T0, T3, T4, T8]) # Check execution order. self.assert_task_dependency_preserved(T0, [T3, T4]) self.assert_task_dependency_preserved(T3, [T8])
def run_update(self): run_task(UpdateRepositoriesTask)
def handle(self, *args, **kwargs): params = {} if kwargs['force_update']: params['force_update'] = True run_task(UpdateRepositoriesTask, **params)
def run_update(self, **kwargs): run_task(UpdateRepositoriesTask, parameters=kwargs)