Improve queue position accuracy and wording in upload email
Mirror and run GitLab CI / build (push) Has been cancelled
Ruff / ruff (push) Has been cancelled

This commit is contained in:
admin
2026-06-14 20:51:34 +00:00
parent 572587bb85
commit e55f36a131
2 changed files with 31 additions and 10 deletions
+1 -1
View File
@@ -13,7 +13,7 @@
<h1 style="color:{accent_color};">Upload Successful</h1>
<p>Dear user,</p>
<p>Your file has been successfully uploaded and is now in our processing queue. This means that our system has received your file, and it is waiting to be processed. We will handle your file as soon as possible.</p>
<p class="success-message">Your current position in the queue is: <span style="color:{accent_color}; font-weight:bold;">{queue_position}</span>. This is the order in which your file will be processed. We appreciate your patience as we work through the queue.</p>
<p class="success-message">Your current position in the queue is: {queue_position_text}. This is the order in which your file will be processed. We appreciate your patience as we work through the queue.</p>
<p>We will notify you once your file has been processed. If you have any urgent needs or further questions, feel free to reach out to our support team.</p>
<div class="contact">
<p>You can contact our support team at <a href="mailto:{contact_email}" style="color:{accent_color};">{contact_email}</a>. Please note that our support team is here to help with any questions or issues you might have.</p>
+30 -9
View File
@@ -70,20 +70,37 @@ def _get_subject(env_var: str, default: str) -> str:
def get_queue_position(task_id: str) -> int:
"""
Estimate the job's position in the queue.
Returns:
- A positive int if we can estimate (1 = first in line).
- 0 if we cannot reliably determine position.
"""
try:
inspect = celery_app.control.inspect()
ready = inspect.active() or {}
reserved = inspect.reserved() or {}
count = 0
for _, tasks in list(ready.values()) + list(reserved.values()):
reserved = inspect.reserved() or {} # queued but not yet running
active = inspect.active() or {} # currently running
# Count tasks ahead of this one in the reserved (waiting) queue
ahead = 0
found = False
for _, tasks in list(reserved.values()):
for t in tasks:
if t.get("id") == task_id:
tid = t.get("id")
if tid == task_id:
found = True
break
count += 1
return max(count + 1, 1)
ahead += 1
if found:
break
# If not found in reserved, it may already be active or not yet visible.
# In that case, treat it as position 1.
if found:
return max(ahead + 1, 1)
else:
return 1
except Exception:
return -1
# If inspection fails, don't guess; caller should use a safe message.
return 0
def send_initial_email(to: str, queue_pos: int):
@@ -103,8 +120,12 @@ def send_initial_email(to: str, queue_pos: int):
if queue_pos > 0:
body += f"Your request is currently number {queue_pos} in the queue.\n"
queue_position_display = (
f'<span style="color:{_accent_color()}; font-weight:bold;">{queue_pos}</span>'
)
else:
body += "Your request has been queued for processing.\n"
queue_position_display = "the queue"
body += (
"\n"
@@ -119,7 +140,7 @@ def send_initial_email(to: str, queue_pos: int):
try:
html = load_template(
"upload_notification_template.html",
queue_position=str(max(queue_pos, 1)),
queue_position_text=queue_position_display,
)
except EmailError as e:
logger.warning("Failed to render upload notification template: %s", e)