def test_task_rescheduled_with_next_offset(self):
        """Check if tasks are rescheduled updating next_offset"""

        handler = CompletedJobHandler(self.task_scheduler)

        task = self.registry.add('mytask', 'git', 'commit', {})
        result = JobResult(0,
                           'mytask',
                           'git',
                           'commit',
                           'FFFFFFFF',
                           1392185439.0,
                           9,
                           offset=1000)
        event = JobEvent(JobEventType.COMPLETED, 0, 'mytask', result)

        handled = handler(event)
        self.assertEqual(handled, True)
        self.assertEqual(task.status, TaskStatus.SCHEDULED)

        # Both fields are updated to the last value received
        # within the result
        self.assertEqual(task.backend_args['next_from_date'],
                         datetime.datetime(2014, 2, 12, 6, 10, 39, tzinfo=UTC))
        self.assertEqual(task.backend_args['next_offset'], 1000)
    def test_task_rescheduled_with_next_offset(self):
        """Check if tasks are rescheduled updating next_offset"""

        handler = CompletedJobHandler(self.task_scheduler)

        task = self.registry.add('mytask', 'git', 'commit', {})
        result = JobResult(0, 1, 'mytask', 'git', 'commit')

        summary = Summary()
        summary.fetched = 10
        summary.last_updated_on = datetime.datetime(2010, 1, 1, 1, 0, 0, tzinfo=UTC)
        summary.max_updated_on = datetime.datetime(2014, 2, 12, 6, 10, 39, tzinfo=UTC)
        summary.last_offset = 800
        summary.max_offset = 1000
        result.summary = summary

        event = JobEvent(JobEventType.COMPLETED, 0, 'mytask', result)

        handled = handler(event)
        self.assertEqual(handled, True)
        self.assertEqual(task.status, TaskStatus.SCHEDULED)

        # Both fields are updated to the max value received
        # within the result
        self.assertEqual(task.backend_args['next_from_date'],
                         datetime.datetime(2014, 2, 12, 6, 10, 39, tzinfo=UTC))
        self.assertEqual(task.backend_args['next_offset'], 1000)
Esempio n. 3
0
    def test_task_rescheduled_no_new_items(self):
        """Check if tasks are rescheduled when no items where generated before"""

        handler = CompletedJobHandler(self.task_scheduler)

        _ = self.task_scheduler.registry.add('mytask', 'git', 'commit', {})
        result = JobResult(0, 1, 'mytask', 'git', 'commit')

        summary = Summary()
        summary.fetched = 0
        summary.max_updated_on = None
        summary.max_offset = None
        result.summary = summary

        event = JobEvent(JobEventType.COMPLETED, 0, 'mytask', result)

        handled = handler(event)
        self.assertEqual(handled, True)

        task = self.task_scheduler.registry.get('mytask')
        self.assertEqual(task.status, TaskStatus.SCHEDULED)

        # Both fields are not updated
        self.assertNotIn('next_from_date', task.backend_args)
        self.assertNotIn('next_offset', task.backend_args)
Esempio n. 4
0
    def test_task_rescheduling(self):
        """Check if the task related to the event is re-scheduled"""

        handler = CompletedJobHandler(self.task_scheduler)

        _ = self.registry.add('mytask', 'git', 'commit', {})

        result = JobResult(0, 1, 'mytask', 'git', 'commit')

        summary = Summary()
        summary.fetched = 10
        summary.last_updated_on = datetime.datetime(2010,
                                                    1,
                                                    1,
                                                    1,
                                                    0,
                                                    0,
                                                    tzinfo=UTC)
        summary.max_updated_on = datetime.datetime(2014,
                                                   2,
                                                   12,
                                                   6,
                                                   10,
                                                   39,
                                                   tzinfo=UTC)
        result.summary = summary

        event = JobEvent(JobEventType.COMPLETED, 0, 'mytask', result)

        handled = handler(event)
        self.assertEqual(handled, True)

        task = self.registry.get('mytask')
        self.assertEqual(task.status, TaskStatus.SCHEDULED)
    def test_ignore_orphan_event(self):
        """Check if an orphan event is ignored"""

        handler = CompletedJobHandler(self.task_scheduler)

        result = JobResult(0, 1, 'mytask', 'git', 'commit')
        event = JobEvent(JobEventType.COMPLETED, 0, 'mytask', result)

        handled = handler(event)
        self.assertEqual(handled, False)
    def test_task_rescheduling(self):
        """Check if the task related to the event is re-scheduled"""

        handler = CompletedJobHandler(self.task_scheduler)

        task = self.registry.add('mytask', 'git', 'commit', {})
        result = JobResult(0, 'mytask', 'git', 'commit',
                           'FFFFFFFF', 1392185439.0, 9)
        event = JobEvent(JobEventType.COMPLETED, 0, 'mytask', result)

        handled = handler(event)
        self.assertEqual(handled, True)
        self.assertEqual(task.status, TaskStatus.SCHEDULED)
Esempio n. 7
0
    def test_ignore_event_on_task_registry_error(self, mock_redis_get):
        """Check if an event is ignored when a TaskRegistryError is thrown"""

        mock_redis_get.side_effect = RedisError

        self.task_scheduler.registry.add('mytask', 'git', 'commit', {})

        handler = CompletedJobHandler(self.task_scheduler)
        result = JobResult(0, 1, 'mytask', 'git', 'commit')
        event = JobEvent(JobEventType.COMPLETED, 0, 'mytask', result)

        handled = handler(event)
        self.assertEqual(handled, False)
    def test_task_not_rescheduled_archive_task(self):
        """Check if archive tasks are not rescheduled"""

        handler = CompletedJobHandler(self.task_scheduler)

        archiving_cfg = ArchivingTaskConfig('/tmp/archive', True)
        task = self.registry.add('mytask', 'git', 'commit', {},
                                 archiving_cfg=archiving_cfg)
        result = JobResult(0, 'mytask', 'git', 'commit',
                           'FFFFFFFF', 1392185439.0, 9)
        event = JobEvent(JobEventType.COMPLETED, 0, 'mytask', result)

        handled = handler(event)
        self.assertEqual(handled, True)
        self.assertEqual(task.status, TaskStatus.COMPLETED)
    def test_task_not_rescheduled_age_limit(self):
        """Check if the task is not re-scheduled when age reaches its limit"""

        handler = CompletedJobHandler(self.task_scheduler)

        scheduler_opts = SchedulingTaskConfig(delay=0, max_retries=0, max_age=3)
        task = self.registry.add('mytask', 'git', 'commit', {},
                                 scheduling_cfg=scheduler_opts)
        # Force the age to its pre-defined limit
        task.age = 3

        result = JobResult(0, 'mytask', 'git', 'commit',
                           'FFFFFFFF', 1392185439.0, 9)
        event = JobEvent(JobEventType.COMPLETED, 0, 'mytask', result)

        handled = handler(event)
        self.assertEqual(handled, True)
        self.assertEqual(task.status, TaskStatus.COMPLETED)
    def test_task_rescheduling_unlimited_age(self):
        """Check if the task is re-scheduled when unlimited age is set"""

        handler = CompletedJobHandler(self.task_scheduler)

        scheduler_opts = SchedulingTaskConfig(delay=0, max_retries=0, max_age=None)
        task = self.registry.add('mytask', 'git', 'commit', {},
                                 scheduling_cfg=scheduler_opts)
        # Force the age to be large value
        task.age = 1000000

        result = JobResult(0, 'mytask', 'git', 'commit',
                           'FFFFFFFF', 1392185439.0, 9)
        event = JobEvent(JobEventType.COMPLETED, 0, 'mytask', result)

        handled = handler(event)
        self.assertEqual(handled, True)
        self.assertEqual(task.status, TaskStatus.SCHEDULED)
Esempio n. 11
0
    def test_task_not_rescheduled_age_limit(self):
        """Check if the task is not re-scheduled when age reaches its limit"""

        handler = CompletedJobHandler(self.task_scheduler)

        scheduler_opts = SchedulingTaskConfig(delay=0,
                                              max_retries=0,
                                              max_age=3)
        task = self.task_scheduler.registry.add('mytask',
                                                'git',
                                                'commit', {},
                                                scheduling_cfg=scheduler_opts)
        # Force the age to its pre-defined limit
        task.age = 3
        self.task_scheduler.registry.update('mytask', task)

        result = JobResult(0, 1, 'mytask', 'git', 'commit')

        summary = Summary()
        summary.fetched = 10
        summary.last_updated_on = datetime.datetime(2010,
                                                    1,
                                                    1,
                                                    1,
                                                    0,
                                                    0,
                                                    tzinfo=UTC)
        summary.max_updated_on = datetime.datetime(2014,
                                                   2,
                                                   12,
                                                   6,
                                                   10,
                                                   39,
                                                   tzinfo=UTC)
        result.summary = summary

        event = JobEvent(JobEventType.COMPLETED, 0, 'mytask', result)

        handled = handler(event)
        self.assertEqual(handled, True)

        task = self.task_scheduler.registry.get('mytask')
        self.assertEqual(task.status, TaskStatus.COMPLETED)
Esempio n. 12
0
    def test_task_rescheduling_unlimited_age(self):
        """Check if the task is re-scheduled when unlimited age is set"""

        handler = CompletedJobHandler(self.task_scheduler)

        scheduler_opts = SchedulingTaskConfig(delay=0,
                                              max_retries=0,
                                              max_age=None)
        task = self.registry.add('mytask',
                                 'git',
                                 'commit', {},
                                 scheduling_cfg=scheduler_opts)
        # Force the age to be large value
        task.age = 1000000

        result = JobResult(0, 1, 'mytask', 'git', 'commit')

        summary = Summary()
        summary.fetched = 10
        summary.last_updated_on = datetime.datetime(2010,
                                                    1,
                                                    1,
                                                    1,
                                                    0,
                                                    0,
                                                    tzinfo=UTC)
        summary.max_updated_on = datetime.datetime(2014,
                                                   2,
                                                   12,
                                                   6,
                                                   10,
                                                   39,
                                                   tzinfo=UTC)
        result.summary = summary

        event = JobEvent(JobEventType.COMPLETED, 0, 'mytask', result)

        handled = handler(event)
        self.assertEqual(handled, True)

        task = self.registry.get('mytask')
        self.assertEqual(task.status, TaskStatus.SCHEDULED)
    def test_task_not_rescheduled_archive_task(self):
        """Check if archive tasks are not rescheduled"""

        handler = CompletedJobHandler(self.task_scheduler)

        archiving_cfg = ArchivingTaskConfig('/tmp/archive', True)
        task = self.registry.add('mytask', 'git', 'commit', {},
                                 archiving_cfg=archiving_cfg)

        result = JobResult(0, 1, 'mytask', 'git', 'commit')

        summary = Summary()
        summary.fetched = 10
        summary.last_updated_on = datetime.datetime(2010, 1, 1, 1, 0, 0, tzinfo=UTC)
        summary.max_updated_on = datetime.datetime(2014, 2, 12, 6, 10, 39, tzinfo=UTC)
        result.summary = summary

        event = JobEvent(JobEventType.COMPLETED, 0, 'mytask', result)

        handled = handler(event)
        self.assertEqual(handled, True)
        self.assertEqual(task.status, TaskStatus.COMPLETED)
Esempio n. 14
0
    def test_task_reset_num_failures(self):
        """Check if the number of failures is reset if the task is successful"""

        handler = CompletedJobHandler(self.task_scheduler)

        task = self.task_scheduler.registry.add('mytask', 'git', 'commit', {})

        # Force to a pre-defined number of failures
        task.num_failures = 2

        result = JobResult(0, 1, 'mytask', 'git', 'commit')

        summary = Summary()
        summary.fetched = 10
        summary.last_updated_on = datetime.datetime(2010,
                                                    1,
                                                    1,
                                                    1,
                                                    0,
                                                    0,
                                                    tzinfo=UTC)
        summary.max_updated_on = datetime.datetime(2014,
                                                   2,
                                                   12,
                                                   6,
                                                   10,
                                                   39,
                                                   tzinfo=UTC)
        result.summary = summary

        event = JobEvent(JobEventType.COMPLETED, 0, 'mytask', result)

        handled = handler(event)
        self.assertEqual(handled, True)

        task = self.task_scheduler.registry.get('mytask')
        self.assertEqual(task.status, TaskStatus.SCHEDULED)
        self.assertEqual(task.num_failures, 0)
    def test_initialization(self):
        """Check if the handler is correctly initialized"""

        handler = CompletedJobHandler(self.task_scheduler)
        self.assertEqual(handler.task_scheduler, self.task_scheduler)