Ejemplo n.º 1
0
 def test_celery_task_should_have_rightly_set_expires_time_if_stale_time_limit_is_set_in_task_call(
         self):
     sum_task.apply_async(args=(5, 8), stale_time_limit=100)
     celery_task_log = CeleryTaskLog.objects.get()
     assert_equal(celery_task_log.estimated_time_of_first_arrival, now())
     assert_equal(celery_task_log.stale, now() + timedelta(seconds=100))
     assert_equal(celery_task_log.expires, now() + timedelta(seconds=90))
Ejemplo n.º 2
0
 def test_apply_task_with_related_objects_should_be_stored(self, user):
     sum_task.apply_async(args=(5, 8), related_objects=[user])
     assert_equal(CeleryTaskLog.objects.count(), 1)
     assert_equal(CeleryTaskLog.objects.get().state,
                  CeleryTaskLogState.SUCCEEDED)
     assert_equal(CeleryTaskLog.objects.get().related_objects.get().object,
                  user)
Ejemplo n.º 3
0
 def test_celery_task_should_be_logged(self):
     sum_task.apply_async(args=(5, 8))
     assert_equal(CeleryTaskLog.objects.count(), 1)
     assert_equal(CeleryTaskLog.objects.get().state,
                  CeleryTaskLogState.SUCCEEDED)
     assert_equal(CeleryTaskRunLog.objects.count(), 1)
     assert_equal(CeleryTaskRunLog.objects.get().state,
                  CeleryTaskRunLogState.SUCCEEDED)
Ejemplo n.º 4
0
 def test_stale_waiting_celery_task_should_be_set_as_failed_with_command(
         self):
     sum_task.apply_async(args=(5, 8))
     celery_task_log = CeleryTaskLog.objects.create(
         celery_task_id='random id',
         name='error_task',
         queue_name='default',
         input='',
         task_args=[],
         task_kwargs={},
         estimated_time_of_first_arrival=now() - timedelta(minutes=5),
         expires=now() - timedelta(minutes=4),
         stale=now() - timedelta(minutes=3))
     test_call_command('set_celery_task_log_state')
     assert_equal(celery_task_log.refresh_from_db().state,
                  CeleryTaskLogState.EXPIRED)
     assert_false(CeleryTaskLog.objects.filter_processing().exists())
Ejemplo n.º 5
0
    def test_stale_succeded_celery_task_should_not_be_set_as_succeeded_with_command(
            self):
        sum_task.apply_async(args=(5, 8))
        celery_task_log = CeleryTaskLog.objects.create(
            celery_task_id='random id',
            name='error_task',
            queue_name='default',
            input='',
            task_args=[],
            task_kwargs={},
            estimated_time_of_first_arrival=now() - timedelta(minutes=5),
            expires=now() - timedelta(minutes=4),
            stale=now() - timedelta(minutes=3))
        CeleryTaskRunLog.objects.create(celery_task_id='random id',
                                        name='error_task',
                                        state=CeleryTaskRunLogState.SUCCEEDED,
                                        task_args=[],
                                        task_kwargs={},
                                        retries=0)

        test_call_command('set_celery_task_log_state')
        assert_equal(celery_task_log.refresh_from_db().state,
                     CeleryTaskLogState.SUCCEEDED)
Ejemplo n.º 6
0
 def test_celery_task_should_have_rightly_set_expires_time(self):
     sum_task.apply_async(args=(5, 8))
     celery_task_log = CeleryTaskLog.objects.get()
     assert_equal(celery_task_log.estimated_time_of_first_arrival, now())
     assert_equal(celery_task_log.expires, now() + timedelta(seconds=20))
     assert_equal(celery_task_log.stale, now() + timedelta(seconds=30))