def test_failed_task_rescheduled_no_new_items(self):
        """Check if tasks are rescheduled when no items where generated before"""

        handler = FailedJobHandler(self.task_scheduler)

        scheduler_opts = SchedulingTaskConfig(delay=0, max_retries=3)
        task = self.registry.add('mytask', 'git', 'commit', {},
                                 scheduling_cfg=scheduler_opts)

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

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

        payload = {
            'error': "Error",
            'result': result
        }
        event = JobEvent(JobEventType.FAILURE, 0, 'mytask', payload)

        handled = handler(event)
        self.assertEqual(handled, True)
        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)
    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)
    def test_failed_task_rescheduled_with_next_offset(self):
        """Check if failed tasks are rescheduled updating next_offset"""

        handler = FailedJobHandler(self.task_scheduler)

        scheduler_opts = SchedulingTaskConfig(delay=0, max_retries=3)
        task = self.registry.add('mytask', 'git', 'commit', {},
                                 scheduling_cfg=scheduler_opts)

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

        summary = Summary()
        summary.fetched = 2
        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

        payload = {
            'error': "Error",
            'result': result
        }
        event = JobEvent(JobEventType.FAILURE, 0, 'mytask', payload)

        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)
        self.assertEqual(task.num_failures, 1)
示例#4
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)