Skip to content

Add retries to sha256 checksum calculation task #1937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions dandiapi/api/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from celery import shared_task
from celery.exceptions import SoftTimeLimitExceeded
from celery.utils.log import get_task_logger

from dandiapi.api.doi import delete_doi
Expand All @@ -15,6 +18,9 @@
from dandiapi.api.models import Asset, AssetBlob, Version
from dandiapi.api.models.dandiset import Dandiset

if TYPE_CHECKING:
from uuid import UUID

logger = get_task_logger(__name__)


Expand All @@ -26,10 +32,16 @@ def remove_asset_blob_embargoed_tag_task(blob_id: str) -> None:
remove_asset_blob_embargoed_tag(asset_blob)


@shared_task(queue='calculate_sha256', soft_time_limit=86_400)
def calculate_sha256(blob_id: str) -> None:
@shared_task(
queue='calculate_sha256',
soft_time_limit=86_400, # 24 hours
autoretry_for=(SoftTimeLimitExceeded,),
retry_backoff=True,
max_retries=3,
)
def calculate_sha256(blob_id: str | UUID) -> None:
asset_blob = AssetBlob.objects.get(blob_id=blob_id)
logger.info('Found AssetBlob %s', blob_id)
logger.info('Calculating sha256 checksum for asset blob %s', blob_id)
sha256 = asset_blob.blob.storage.sha256_checksum(asset_blob.blob.name)

# TODO: Run dandi-cli validation
Expand Down