|
22 | 22 | from dandiapi.analytics.tasks import collect_s3_log_records_task
|
23 | 23 | from dandiapi.api.mail import send_dandisets_to_unembargo_message, send_pending_users_message
|
24 | 24 | from dandiapi.api.models import UserMetadata, Version
|
25 |
| -from dandiapi.api.models.asset import Asset |
| 25 | +from dandiapi.api.models.asset import Asset, AssetBlob |
26 | 26 | from dandiapi.api.models.dandiset import Dandiset
|
27 | 27 | from dandiapi.api.services.metadata import version_aggregate_assets_summary
|
28 | 28 | from dandiapi.api.services.metadata.exceptions import VersionMetadataConcurrentlyModifiedError
|
29 | 29 | from dandiapi.api.tasks import (
|
| 30 | + calculate_sha256, |
30 | 31 | validate_asset_metadata_task,
|
31 | 32 | validate_version_metadata_task,
|
32 | 33 | write_manifest_files,
|
@@ -63,6 +64,19 @@ def aggregate_assets_summary_task(version_id: int):
|
63 | 64 | version_aggregate_assets_summary(version)
|
64 | 65 |
|
65 | 66 |
|
| 67 | +@shared_task(soft_time_limit=30) |
| 68 | +def recalculate_missing_sha256_checksums(): |
| 69 | + blobs_missing = AssetBlob.objects.filter(sha256__isnull=True).values_list('blob_id', flat=True) |
| 70 | + num_missing = blobs_missing.count() |
| 71 | + if num_missing == 0: |
| 72 | + logger.info('No blobs with missing checksums found') |
| 73 | + return |
| 74 | + |
| 75 | + logger.info('Found %s blobs with missing checksums', num_missing) |
| 76 | + for blob_id in blobs_missing: |
| 77 | + calculate_sha256.delay(blob_id) |
| 78 | + |
| 79 | + |
66 | 80 | @shared_task(soft_time_limit=30)
|
67 | 81 | def validate_pending_asset_metadata():
|
68 | 82 | validatable_assets = (
|
@@ -156,3 +170,6 @@ def register_scheduled_tasks(sender: Celery, **kwargs):
|
156 | 170 |
|
157 | 171 | # Process new S3 logs every hour
|
158 | 172 | sender.add_periodic_task(timedelta(hours=1), collect_s3_log_records_task.s())
|
| 173 | + |
| 174 | + # Check for asset blobs with missing sha256 checksums once a day |
| 175 | + sender.add_periodic_task(crontab(hour=3, minute=0), recalculate_missing_sha256_checksums.s()) |
0 commit comments