feat: enrich saved leasing events with bounded Fedresurs details
All checks were successful
Mostovik Backend CI/CD / Tests and lint (push) Successful in 3m26s
Mostovik Backend CI/CD / Build linux/amd64 release images (push) Successful in 3m28s
Mostovik Backend CI/CD / Deploy and verify internal main (push) Has been skipped
Mostovik Backend CI/CD / Deploy dev (push) Successful in 2m3s
All checks were successful
Mostovik Backend CI/CD / Tests and lint (push) Successful in 3m26s
Mostovik Backend CI/CD / Build linux/amd64 release images (push) Successful in 3m28s
Mostovik Backend CI/CD / Deploy and verify internal main (push) Has been skipped
Mostovik Backend CI/CD / Deploy dev (push) Successful in 2m3s
This commit is contained in:
@@ -379,7 +379,13 @@ def parse_fssp_enforcement_proceedings(
|
||||
soft_time_limit=8 * 3600,
|
||||
time_limit=8 * 3600 + 300,
|
||||
)
|
||||
def parse_checko_leasing(self, *, requested_by_id: int | None = None) -> dict:
|
||||
def parse_checko_leasing(
|
||||
self, *, requested_by_id: int | None = None, mode: str = "collection"
|
||||
) -> dict:
|
||||
if mode == "details":
|
||||
return _run_leasing_details(self, requested_by_id=requested_by_id)
|
||||
if mode != "collection":
|
||||
raise SnapshotValidationError("invalid_mode")
|
||||
from apps.parsers.checko_section_snapshots import refresh_checko_section
|
||||
|
||||
return _run_snapshot(
|
||||
@@ -391,6 +397,43 @@ def parse_checko_leasing(self, *, requested_by_id: int | None = None) -> dict:
|
||||
)
|
||||
|
||||
|
||||
def _run_leasing_details(task, *, requested_by_id: int | None) -> dict:
|
||||
"""Detail-only job; never create a collection log or advance full snapshot success."""
|
||||
from apps.parsers.leasing_details import enrich_leasing_details
|
||||
|
||||
job, _ = BackgroundJob.objects.get_or_create(
|
||||
task_id=task.request.id or str(uuid.uuid4()),
|
||||
defaults={
|
||||
"task_name": task.name,
|
||||
"user_id": requested_by_id,
|
||||
"meta": {"source": "checko_leasing", "mode": "details"},
|
||||
},
|
||||
)
|
||||
try:
|
||||
if not _claim_snapshot_job(job, "checko_leasing", task.name):
|
||||
job.refresh_from_db()
|
||||
return job.result or {"status": job.status, "duplicate_delivery": True}
|
||||
job.update_progress(5, "Дополнение сохранённых событий лизинга")
|
||||
result = enrich_leasing_details()
|
||||
job.refresh_from_db()
|
||||
if job.status != JobStatus.STARTED:
|
||||
raise SnapshotValidationError("snapshot_job_no_longer_active")
|
||||
job.meta = {**job.meta, "mode": "details", **result}
|
||||
job.result = {"source": "checko_leasing", "mode": "details", **result}
|
||||
job.save(update_fields=("meta", "result", "updated_at"))
|
||||
if result["error_code"] and not result["records_updated"]:
|
||||
raise SnapshotValidationError(result["error_code"])
|
||||
status = "partial" if result["error_code"] else "success"
|
||||
job.update_progress(100, "Порция дополнения лизинга завершена")
|
||||
job.complete(result={"status": status, **job.result})
|
||||
if result["records_updated"]:
|
||||
transaction.on_commit(_refresh_published_exports)
|
||||
return job.result
|
||||
except Exception as exc:
|
||||
job.fail(error=_snapshot_error_message(exc))
|
||||
raise
|
||||
|
||||
|
||||
@shared_task(
|
||||
bind=True,
|
||||
name="parsers.checko_messages.refresh",
|
||||
|
||||
Reference in New Issue
Block a user