feat: expose Checko section APIs and completion counters

This commit is contained in:
Aleksandr Meshchryakov
2026-10-05 16:45:13 +02:00
parent a517950425
commit 4637b02ddd
26 changed files with 1974 additions and 36 deletions

View File

@@ -10,7 +10,7 @@ from functools import partial
from apps.core.exceptions import ConflictError
from apps.core.models import BackgroundJob, JobStatus
from apps.parsers.budget_registry import BUDGET_SOURCE, refresh_budget_registry
from apps.parsers.models import ParserBatchSequence, ParserLoadLog
from apps.parsers.models import ParserBatchSequence, ParserLoadLog, ParserSourceArtifact
from apps.parsers.registry_snapshots import SnapshotValidationError
from apps.parsers.services import ParserLoadLogService
from apps.parsers.sme_support import SME_SOURCE, refresh_sme_support
@@ -62,7 +62,13 @@ def _complete_snapshot_job(job, load_log, artifact, result) -> dict:
"version": artifact.version or None,
"checksum_sha256": artifact.sha256 or None,
}
if artifact.source in ("sro_membership_check", "fssp_enforcement_proceedings"):
if artifact.source in (
"sro_membership_check",
"fssp_enforcement_proceedings",
"checko_leasing",
"checko_messages",
"checko_licenses",
):
payload.update(artifact.metadata)
job.meta = {
**job.meta,
@@ -83,6 +89,9 @@ def _claim_snapshot_job(job, source, task_name):
"sro_membership_check",
"fedresurs_company_profile",
"fssp_enforcement_proceedings",
"checko_leasing",
"checko_messages",
"checko_licenses",
):
sequence, _ = ParserBatchSequence.objects.get_or_create(source=source)
ParserBatchSequence.objects.select_for_update().get(pk=sequence.pk)
@@ -150,6 +159,32 @@ def _snapshot_error_message(exc: Exception) -> str:
return message
def _attach_rejected_section(job, source, load_log):
if (
source in ("checko_leasing", "checko_messages", "checko_licenses")
and load_log is not None
):
rejected = (
ParserSourceArtifact.objects.filter(
source=source,
load_batch=load_log.batch_id,
status=ParserSourceArtifact.Status.REJECTED,
)
.order_by("-created_at")
.first()
)
if rejected is not None:
job.result = {
**rejected.metadata,
"source": source,
"artifact_id": str(rejected.uid),
"batch_id": load_log.batch_id,
"status": "failure",
}
job.meta = {**job.meta, **rejected.metadata}
job.save(update_fields=["result", "meta", "updated_at"])
def _run_snapshot(
task,
*,
@@ -221,6 +256,7 @@ def _run_snapshot(
if load_log is not None:
ParserLoadLogService.mark_failed(load_log, message)
if job is not None:
_attach_rejected_section(job, source, load_log)
job.fail(error=message)
raise
@@ -326,3 +362,57 @@ def parse_fssp_enforcement_proceedings(
requested_by_id=requested_by_id,
track_progress=True,
)
@shared_task(
bind=True,
name="parsers.checko_leasing.refresh",
soft_time_limit=8 * 3600,
time_limit=8 * 3600 + 300,
)
def parse_checko_leasing(self, *, requested_by_id: int | None = None) -> dict:
from apps.parsers.checko_section_snapshots import refresh_checko_section
return _run_snapshot(
self,
source="checko_leasing",
refresh=partial(refresh_checko_section, source="checko_leasing"),
requested_by_id=requested_by_id,
track_progress=True,
)
@shared_task(
bind=True,
name="parsers.checko_messages.refresh",
soft_time_limit=8 * 3600,
time_limit=8 * 3600 + 300,
)
def parse_checko_messages(self, *, requested_by_id: int | None = None) -> dict:
from apps.parsers.checko_section_snapshots import refresh_checko_section
return _run_snapshot(
self,
source="checko_messages",
refresh=partial(refresh_checko_section, source="checko_messages"),
requested_by_id=requested_by_id,
track_progress=True,
)
@shared_task(
bind=True,
name="parsers.checko_licenses.refresh",
soft_time_limit=8 * 3600,
time_limit=8 * 3600 + 300,
)
def parse_checko_licenses(self, *, requested_by_id: int | None = None) -> dict:
from apps.parsers.checko_section_snapshots import refresh_checko_section
return _run_snapshot(
self,
source="checko_licenses",
refresh=partial(refresh_checko_section, source="checko_licenses"),
requested_by_id=requested_by_id,
track_progress=True,
)