feat(organizations): migrate source storage to polymorphic records

This commit is contained in:
2026-05-19 10:23:53 +02:00
parent 19a7d5a91c
commit 4ca2fa25d5
44 changed files with 7129 additions and 1551 deletions

View File

@@ -1,31 +1,57 @@
"""Celery tasks for organizations snapshots."""
"""Celery tasks for organization source extensions."""
from __future__ import annotations
import logging
from dataclasses import asdict
from celery import shared_task
from organizations.cache import invalidate_organization_api_cache
from organizations.services import OrganizationDataSnapshotRefreshService
from organizations.source_backfill import OrganizationSourceBackfillService
logger = logging.getLogger(__name__)
@shared_task
def refresh_all_organization_data_snapshots(batch_size: int = 100) -> dict:
"""Refresh all organization data snapshots for API v2."""
result = OrganizationDataSnapshotRefreshService.refresh(batch_size=batch_size)
def backfill_all_organization_sources(batch_size: int = 100) -> dict:
"""Backfill all organization source extensions from legacy parser tables."""
result = OrganizationSourceBackfillService.backfill()
invalidate_organization_api_cache()
payload = {"batch_size": batch_size, **asdict(result)}
logger.info("All organization source extensions backfilled: %s", payload)
return payload
@shared_task
def backfill_organization_sources_for_parser_batch(
*,
source: str,
batch_id: int,
batch_size: int = 100,
) -> dict:
"""Backfill source extensions affected by one parser batch."""
result = OrganizationSourceBackfillService.backfill(
source=source,
batch_id=batch_id,
)
invalidate_organization_api_cache()
payload = {
"processed": result.processed,
"created": result.created,
"updated": result.updated,
"source": source,
"batch_id": batch_id,
"batch_size": batch_size,
**asdict(result),
}
logger.info("All organization data snapshots refreshed: %s", payload)
logger.info("Organization source extensions backfilled: %s", payload)
return payload
@shared_task
def refresh_all_organization_data_snapshots(batch_size: int = 100) -> dict:
"""Deprecated compatibility wrapper for the old snapshot schedule."""
return backfill_all_organization_sources(batch_size=batch_size)
@shared_task
def refresh_organization_data_snapshots_for_parser_batch(
*,
@@ -33,19 +59,9 @@ def refresh_organization_data_snapshots_for_parser_batch(
batch_id: int,
batch_size: int = 100,
) -> dict:
"""Refresh snapshots for organizations affected by one parser batch."""
result = OrganizationDataSnapshotRefreshService.refresh_for_parser_batch(
"""Deprecated compatibility wrapper for old parser task imports."""
return backfill_organization_sources_for_parser_batch(
source=source,
batch_id=batch_id,
batch_size=batch_size,
)
invalidate_organization_api_cache()
payload = {
"source": source,
"batch_id": batch_id,
"processed": result.processed,
"created": result.created,
"updated": result.updated,
}
logger.info("Organization data snapshots refreshed: %s", payload)
return payload