From c3bf3cc2aed3ee29e3caf65654e83cdb050a16db Mon Sep 17 00:00:00 2001 From: Kyrylo Kireiev <90455454+KyryloKireiev@users.noreply.github.com> Date: Thu, 13 Jun 2024 13:13:24 +0300 Subject: [PATCH] feat: [AXM-589] Add retry to content generation task (#2574) --- openedx/features/offline_mode/assets_management.py | 3 +++ openedx/features/offline_mode/constants.py | 3 +++ openedx/features/offline_mode/tasks.py | 8 ++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/openedx/features/offline_mode/assets_management.py b/openedx/features/offline_mode/assets_management.py index e8b73e9213e6..3594d31c24c0 100644 --- a/openedx/features/offline_mode/assets_management.py +++ b/openedx/features/offline_mode/assets_management.py @@ -68,6 +68,9 @@ def save_asset_file(temp_dir, xblock, path, filename): def create_subdirectories_for_asset(file_path): + """ + Creates subdirectories for asset. + """ out_dir_name = '/' for dir_name in file_path.split('/')[:-1]: out_dir_name = os.path.join(out_dir_name, dir_name) diff --git a/openedx/features/offline_mode/constants.py b/openedx/features/offline_mode/constants.py index 401d84d0a271..a1337a7029c1 100644 --- a/openedx/features/offline_mode/constants.py +++ b/openedx/features/offline_mode/constants.py @@ -11,3 +11,6 @@ DEFAULT_OFFLINE_SUPPORTED_XBLOCKS = ['html'] OFFLINE_SUPPORTED_XBLOCKS = getattr(settings, 'OFFLINE_SUPPORTED_XBLOCKS', DEFAULT_OFFLINE_SUPPORTED_XBLOCKS) + +RETRY_BACKOFF_INITIAL_TIMEOUT = 60 # one minute +MAX_RETRY_ATTEMPTS = 5 diff --git a/openedx/features/offline_mode/tasks.py b/openedx/features/offline_mode/tasks.py index 75e786f43ca4..bffbe0396a8f 100644 --- a/openedx/features/offline_mode/tasks.py +++ b/openedx/features/offline_mode/tasks.py @@ -7,7 +7,7 @@ from xmodule.modulestore.django import modulestore -from .constants import OFFLINE_SUPPORTED_XBLOCKS +from .constants import MAX_RETRY_ATTEMPTS, OFFLINE_SUPPORTED_XBLOCKS, RETRY_BACKOFF_INITIAL_TIMEOUT from .renderer import XBlockRenderer from .utils import generate_offline_content @@ -25,7 +25,11 @@ def generate_offline_content_for_course(course_id): generate_offline_content_for_block.apply_async([str(xblock.location), html_data]) -@shared_task +@shared_task( + autoretry_for=(Exception,), + retry_backoff=RETRY_BACKOFF_INITIAL_TIMEOUT, + retry_kwargs={'max_retries': MAX_RETRY_ATTEMPTS} +) @set_code_owner_attribute def generate_offline_content_for_block(block_id, html_data): """