fix: recover stale pending monthly ZIP requests
Some checks failed
ERP CI/CD Pipeline / test (push) Has been cancelled
ERP CI/CD Pipeline / Deploy (server git pull + compose) (push) Has been cancelled

Mark stale pending fleet archives as failed after a timeout window and create a fresh request so users receive completion notifications and can download ZIP files again.

Add regression coverage for replacing stale pending service-task archive requests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
mariomitte
2026-08-07 06:34:05 +02:00
parent bf381dcf13
commit 7053ec32f8
2 changed files with 40 additions and 4 deletions

View File

@@ -3055,10 +3055,17 @@ def _request_monthly_archive_generation(*, request, archive_type):
.first()
)
if existing_pending:
return {
'status': 'processing',
'generated_archive_id': str(existing_pending.pk),
}
stale_pending_threshold = timezone.now() - timedelta(minutes=3)
if existing_pending.created_at and existing_pending.created_at < stale_pending_threshold:
existing_pending.is_active = False
existing_pending.status = 'failed'
existing_pending.error_message = 'ZIP zahtjev je ostao predugo u pending statusu; pokrece se novi zahtjev.'
existing_pending.save(update_fields=['is_active', 'status', 'error_message', 'updated_at'])
else:
return {
'status': 'processing',
'generated_archive_id': str(existing_pending.pk),
}
generated_archive = GeneratedFleetArchive.objects.create(
requested_by=request.user,