some fix sms retry

This commit is contained in:
javad committed 2026-09-16 14:45:10 +03:30
1 parent 0ed677e5fc
commit 863ca89485
3 files changed
+206 -8

No files matched your search

@@ -20,9 +20,10 @@ from apps.tickets.models import Ticket
logger = logging.getLogger(__name__)
DEFINITIVE_DELIVERY_RETRY_EVENT = "STAFF_TICKET_CREATED"
DEFINITIVE_DELIVERY_RETRY_STATUSES = {
NotificationJob.DeliveryStatus.UNDELIVERED,
NotificationJob.DeliveryStatus.EXPIRED,
SAFE_0098_DELIVERY_RETRY_RESULTS = {
(NotificationJob.DeliveryStatus.UNDELIVERED, "6"),
(NotificationJob.DeliveryStatus.EXPIRED, "7"),
(NotificationJob.DeliveryStatus.ERROR, "-31"),
}
def _magic_link(job, reason):
@@ -175,6 +176,10 @@ def _delivery_retry_dedupe_key(job):
return f"{job.dedupe_key[:200-len(suffix)]}{suffix}"
def _is_safe_0098_delivery_retry_result(job):
return (job.delivery_status, (job.delivery_status_code or "").strip()) in SAFE_0098_DELIVERY_RETRY_RESULTS
def _schedule_definitive_delivery_retry(job):
"""Schedule exactly one delayed resend for a definitive individual-ticket failure."""
if (
@@ -184,7 +189,7 @@ def _schedule_definitive_delivery_retry(job):
or not job.ticket_id
or job.ticket.group_dispatch_id
or not job.delivery_is_final
or job.delivery_status not in DEFINITIVE_DELIVERY_RETRY_STATUSES
or not _is_safe_0098_delivery_retry_result(job)
):
return None
sent_at = job.sent_at or job.created_at
@@ -268,6 +273,13 @@ def _process_delivery_checks(options):
else:
job.delivery_status = result.status if result.status in NotificationJob.DeliveryStatus.values else NotificationJob.DeliveryStatus.ERROR
job.delivery_next_check_at = None
# 0098SMS code 6 remains provisional during polling. Once the
# complete monitoring window is exhausted it is safe to treat
# this exact result as terminal for the single delayed resend.
job.delivery_is_final = (
job.delivery_status == NotificationJob.DeliveryStatus.UNDELIVERED
and job.delivery_status_code == "6"
)
job.delivery_description = f"{result.description} نتیجه پس از {job.delivery_check_attempts} نوبت استعلام در بازه پایش نهایی شد."[:500]
job.save(update_fields=[
"delivery_status", "delivery_status_code", "delivery_description",