示例#1
0
    def test_tasks_funs_sort(self):
        """ Testing tha we can sort functions as tasks
        """

        def task1():
            pass

        def task2():
            pass

        def task3():
            pass

        def task4():
            pass

        def task5():
            pass

        def task6():
            pass

        res = topsort([(task1, task2),
                       (task3, task4),
                       (task5, task6),
                       (task1, task3),
                       (task1, task5),
                       (task1, task6),
                       (task2, task5)])

        logger.info('sorted: %s', str(res))
        self.assertEqual(res, [task1, task2, task3, task5, task4, task6])
示例#2
0
    def test_tasks_methods_sort(self):
        """ Testing tha we can sort methods as tasks
        """

        class SomeClass(object):
            def task1(self):
                pass

            def task2(self):
                pass

            def task3(self):
                pass

            def task4(self):
                pass

        def task5():
            pass

        def task6():
            pass

        o1 = SomeClass()

        res = topsort([(o1.task1, o1.task2),
                       (o1.task3, o1.task4),
                       (task5, task6),
                       (o1.task1, o1.task3),
                       (o1.task1, task5),
                       (o1.task1, task6),
                       (o1.task2, task5)])

        logger.info('sorted: %s', str(res))
        self.assertEqual(res, [o1.task1, o1.task2, o1.task3, task5, o1.task4, task6])
示例#3
0
 def schedule(self):
     """ Schedule the tasks that must be run
     """
     try:
         if self._target_tasks:
             logger.debug('scheduling tasks...')
             tasks_to_run = [t for t in topsort(self._target_tasks) if t]
             self._tasks_to_run = tasks_to_run
         else:
             self._tasks_to_run = []
     except CycleError, e:
         logger.critical('cycle error:')
         logger.critical('%s', str(e))
         raise SchedulerTaskException('cycle error')