def test_check_concurrency(self): # Operation without concurrency defaults to infinite concurrency operation = OperationFactory() operation_run = OperationRunFactory(operation=operation) assert operation_run.check_concurrency() is True # Operation with concurrency and operation run with operation runs operation.concurrency = 2 operation.save() # No running operation runs assert operation_run.check_concurrency() is True # One operation run operation_run1 = OperationRunFactory(operation=operation) assert operation_run.check_concurrency() is True # One operation run with RUNNING status operation_run1.status = OperationStatuses.RUNNING operation_run1.save() assert operation_run.check_concurrency() is True # Second operation run operation_run2 = OperationRunFactory(operation=operation) assert operation_run.check_concurrency() is True # Second operation run with RUNNING status operation_run2.status = OperationStatuses.RUNNING operation_run2.save() assert operation_run.check_concurrency() is False
def test_check_concurrency(self): # Operation without concurrency defaults to infinite concurrency operation = OperationFactory() operation_run = OperationRunFactory(operation=operation) assert operation_run.check_concurrency() is True # Operation with concurrency and operation run with operation runs operation.concurrency = 2 operation.save() # No running operation runs assert operation_run.check_concurrency() is True # One operation run operation_run1 = OperationRunFactory(operation=operation) assert operation_run.check_concurrency() is True # One operation run with RUNNING status OperationRunStatus.objects.create(status=OperationStatuses.RUNNING, operation_run=operation_run1) assert operation_run.check_concurrency() is True # Second operation run operation_run2 = OperationRunFactory(operation=operation) assert operation_run.check_concurrency() is True # Second operation run with RUNNING status OperationRunStatus.objects.create(status=OperationStatuses.RUNNING, operation_run=operation_run2) assert operation_run.check_concurrency() is False
def test_get_countdown(self): operation = OperationFactory(retry_delay=5) assert operation.get_countdown(1) == 5 assert operation.get_countdown(2) == 5 # Test exponential backoff operation.retry_exponential_backoff = True operation.max_retry_delay = 24 operation.save() assert operation.get_countdown(1) == 5 assert operation.get_countdown(2) == 5 assert operation.get_countdown(3) == 8 assert operation.get_countdown(4) == 16 assert operation.get_countdown(5) == 24 # Max retry delay
def test_get_run_params(self): operation = OperationFactory() assert operation.get_run_params() == {} operation.queue = 'dummy_queue' operation.save() assert operation.get_run_params() == {'queue': 'dummy_queue'} operation.timeout = 10 operation.save() assert operation.get_run_params() == { 'queue': 'dummy_queue', 'soft_time_limit': 10, 'time_limit': settings.CELERY_HARD_TIME_LIMIT_DELAY + 10, } operation.execute_at = timezone.now() + timedelta(hours=1) operation.save() assert operation.get_run_params() == { 'queue': 'dummy_queue', 'soft_time_limit': 10, 'time_limit': settings.CELERY_HARD_TIME_LIMIT_DELAY + 10, 'eta': operation.execute_at }
def test_get_run_params(self): operation = OperationFactory() assert operation.get_run_params() == {} operation.celery_queue = 'dummy_queue' operation.save() assert operation.get_run_params() == {'queue': 'dummy_queue'} operation.timeout = 10 operation.save() assert operation.get_run_params() == { 'queue': 'dummy_queue', 'soft_time_limit': 10, 'time_limit': settings.CELERY_HARD_TIME_LIMIT_DELAY + 10, } operation.execute_at = timezone.now() + timedelta(hours=1) operation.save() assert operation.get_run_params() == { 'queue': 'dummy_queue', 'soft_time_limit': 10, 'time_limit': settings.CELERY_HARD_TIME_LIMIT_DELAY + 10, 'eta': operation.execute_at }