def test_retry_too_many(): with pytest.raises(MaxRetriesExceededError): _retry( task=execute_job, signature_kwargs={"kwargs": { "foo": "bar" }}, retries=100_000, )
def test_retry_many(): with capture_on_commit_callbacks() as callbacks: _retry( task=execute_job, signature_kwargs={"kwargs": { "foo": "bar" }}, retries=10, ) new_task = callbacks[0].__self__ assert new_task.options["queue"] == "acks-late-micro-short-delay" assert new_task.kwargs == {"foo": "bar", "retries": 11}
def test_retry_initial_options(): with capture_on_commit_callbacks() as callbacks: _retry( task=execute_job, signature_kwargs={ "kwargs": { "foo": "bar" }, "options": { "queue": "mine" }, }, retries=0, ) new_task = callbacks[0].__self__ assert new_task.options["queue"] == "mine-delay" assert new_task.kwargs == {"foo": "bar", "retries": 1}
def wait_for_build_completion(*, build_pk, retries=0): Build = apps.get_model( # noqa: N806 app_label="codebuild", model_name="Build") build = Build.objects.get(pk=build_pk) with transaction.atomic(): build.refresh_status() if build.status == build.BuildStatusChoices.IN_PROGRESS: _retry( task=wait_for_build_completion, signature_kwargs={"kwargs": { "build_pk": build_pk }}, retries=retries, ) return else: build.refresh_logs() build.save() if build.status == build.BuildStatusChoices.SUCCEEDED: on_commit(lambda: add_image_to_algorithm.apply_async( kwargs={"build_pk": str(build_pk)}))