Skip to content

Commit

Permalink
Merge pull request #1937 from dandi/sha256-checksum-cron-job
Browse files Browse the repository at this point in the history
Add retries to sha256 checksum calculation task
  • Loading branch information
jjnesbitt authored Jul 30, 2024
2 parents a3f2d9d + d4d5010 commit 095afba
Showing 1 changed file with 15 additions and 3 deletions.
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

0 comments on commit 095afba

Please sign in to comment.