You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Known work around Bug: Email delay-previously emails generated by examining a name had a 5-minute delay. #21835
Priority 3: Email delay-previously emails generated by examining a name had a 5-minute delay. This was helpful when examining as any mistakes (forgot to put condition on, made error in examining, etc.) wouldn’t result in multiple outputs that are confusing for the client. Preference for a short delay that only generates the last email. (Frequency 100%) Time cost: approx. 20-30min/week
Update from Joshua:
• The removal of the output delay creates confusion for clients if an examiner were to catch a mistake and go back to fix it (generates multiple different results emails to clients, who then call or email in confusion which creates a cascade effect). Even a few minutes delay for output generation would help reduce this.
Regarding this topic below, could you please let us know what would be a desirable duration for this delay? We could do 5, 10, 15 minutes, whatever would best fit the Name Examiners needs.
Update from Joshua:
• The removal of the output delay creates confusion for clients if an examiner were to catch a mistake and go back to fix it (generates multiple different results emails to clients, who then call or email in confusion which creates a cascade effect). Even a few minutes delay for output generation would help reduce this.
NameX API uses the Flask Framework running on a Gunicorn WSGI Server
Why its not possible to us async/await on each email for 5 minutes
Flask on its own is single-threaded (blocking) and does not natively support asynchronous operations across requests - only within them (can await a database operation, but cant schedule it - it will be cancelled once the request ends since flask handles 1 request at a time).
In production, a Gunicorn WSGI Server allows Flask to be concurrent (multiple requests at once)
Gunicorn employs several instances of the app called workers that run independently of each other
These workers can be sync (default) or gevent (green threads)
sync is the default worker type and the one that is used in our API
In this scenario, each NR needs to wait for 5 minutes so it needs to schedule an async task that outlives itself. In the Flask Link provided, under Background Tasks, it states that this is not possible on a WSGI server (1 request-response cycle per worker).
To get the desired behavior (non-blocking waiting for 5 minutes for each email)
Change the Gunicorn worker to be of type gevent to allow for async operations
This would change the way the Server works - it would support asynchronous operations (have an event loop, gEVENT)
The section When to use Quart instead in the Flask docs seem to imply this is more of a work-around.
Spawn a separate thread for async operations
Spawn a separate thread with an event loop to handle all asynchronous tasks.
This approach adds a layer of complexity - API would become multithreaded with a main sync thread and another async thread where emails tasks are scheduled.
Use Celery to get the async effect
Celery is a separate process that acts as a task queue.
API would send asynchronous tasks to this separate process.
The recommended way, involves adding another dependency and separate running process to the api
.
Use a Cron Job to get the async effect
Any time an email needs to be sent, it is written to disk in the database.
A cron job then reads from this database every 5 minutes (or even at the end of every day) and determines what emails need to be sent.
Note: The code changes only apply to emails that are approved, conditionally approved, or rejected. But it is probably good to confirm the others are working as expected too (before-expiry, expiry, consent-required, paid, refund, renewal, & upgrade = 7 regression tests -> 1 of each is sufficient here as none of the code changes touched the email decision tree or those types of emails in general).
Note: An email event in this context refers to approving, conditionally approving, or rejecting an NR (triggering the email scheduling).
Note: The debounce window is 5 minutes from the most recent email event. Therefore it is possible to keep on delaying the email for the nr if the nr is reset and another email event occurs within 5 minutes (approve, reject, approve, reject...)
Note: If an email event occurs and then reset without another email event occuring within 5 minutes, the email will still send. Supporting this is outside the scope of this ticket and will be completed in 28997.
Note: Testing this ticket would be a lot easier with read access to namex-emailer-pending-send-queue-test and the namex-emailer-test logs.
For approved, conditionally approved, and rejected:
Scenario 1 (no change)
Email event occurs and the NR is not reset within 5 minutes
→ Should only receive one email (not within 5 minute debounce window)
Scenario 2 (no change)
Email event occurs and the NR is reset with < 5 min between email event and reset
→ Should only receive one email (not ideal as within debounce window, see note)
Scenario 3 (no change)
Email event occurs and the NR is reset with > 5 min between email event and reset
→ Should only receive one email (not within 5 minute debounce window)
Scenario 4 (changed behavior)
Email event occurs → NR is reset → another email event happens < 5 min later
→ Should only receive the latest email
Scenario 5 (changed behavior)
Multiple email events come in (all within 5 minutes of the one before it)
→ Should only receive the latest email
Scenario 6 (no change)
Two or more email events occur, but > 5 minutes have passed between them
→ Should receive both (or all) emails, since they are outside the debounce window
Activity
ozamani9gh commentedon Jun 25, 2024
Update from Joshua:
• The removal of the output delay creates confusion for clients if an examiner were to catch a mistake and go back to fix it (generates multiple different results emails to clients, who then call or email in confusion which creates a cascade effect). Even a few minutes delay for output generation would help reduce this.
ozamani9gh commentedon Jun 27, 2024
@Mihai-QuickSilverDev reach out to Joshua and get the exact delay he wants, we suggest 10 or 15 minutes.
Mihai-QuickSilverDev commentedon Jun 28, 2024
Message sent to Joshua on June 28, 2024, 9 AM:
Hi Joshua,
Regarding this topic below, could you please let us know what would be a desirable duration for this delay? We could do 5, 10, 15 minutes, whatever would best fit the Name Examiners needs.
Update from Joshua:
• The removal of the output delay creates confusion for clients if an examiner were to catch a mistake and go back to fix it (generates multiple different results emails to clients, who then call or email in confusion which creates a cascade effect). Even a few minutes delay for output generation would help reduce this.
Thank you,
ozamani9gh commentedon Jul 2, 2024
Joshua stated 5 minutes is sufficient
EPortman commentedon Jul 4, 2024
Clients are emailed about their NRs in the following scenarios:
EPortman commentedon Jul 15, 2024
Async Operations with Flask Framework: https://flask.palletsprojects.com/en/3.0.x/async-await/#
Async Operations with Gunicorn Server: https://docs.gunicorn.org/en/latest/design.html
NameX API uses the Flask Framework running on a
Gunicorn WSGI ServerWhy its not possible to us async/await on each email for 5 minutes
Flask on its own is single-threaded (blocking) and does not natively support asynchronous operations across requests - only within them (can await a database operation, but cant schedule it - it will be cancelled once the request ends since flask handles 1 request at a time).
workersthat run independently of each otherworkerscan besync(default) orgevent(green threads)syncis the default worker type and the one that is used in our APIBackground Tasks, it states that this is not possible on a WSGI server (1 request-response cycle per worker).To get the desired behavior (non-blocking waiting for 5 minutes for each email)
Change the Gunicorn worker to be of type
geventto allow for async operationsWhen to use Quart insteadin the Flask docs seem to imply this is more of a work-around.Spawn a
separate threadfor async operationsUse
Celeryto get the async effect.
Use a
Cron Jobto get the async effectEPortman commentedon Jul 15, 2024
A good resource for this topic: https://testdriven.io/blog/flask-async/

EPortman commentedon Jun 12, 2025
Quality Assurance
Note: The code changes only apply to emails that are approved, conditionally approved, or rejected. But it is probably good to confirm the others are working as expected too (before-expiry, expiry, consent-required, paid, refund, renewal, & upgrade = 7 regression tests -> 1 of each is sufficient here as none of the code changes touched the email decision tree or those types of emails in general).
Note: An email event in this context refers to approving, conditionally approving, or rejecting an NR (triggering the email scheduling).
Note: The debounce window is 5 minutes from the most recent email event. Therefore it is possible to keep on delaying the email for the nr if the nr is reset and another email event occurs within 5 minutes (approve, reject, approve, reject...)
Note: If an email event occurs and then reset without another email event occuring within 5 minutes, the email will still send. Supporting this is outside the scope of this ticket and will be completed in 28997.
Note: Testing this ticket would be a lot easier with read access to
namex-emailer-pending-send-queue-testand thenamex-emailer-testlogs.For approved, conditionally approved, and rejected:
Scenario 1 (no change)
Email event occurs and the NR is not reset within 5 minutes
→ Should only receive one email (not within 5 minute debounce window)
Scenario 2 (no change)
Email event occurs and the NR is reset with < 5 min between email event and reset
→ Should only receive one email (not ideal as within debounce window, see note)
Scenario 3 (no change)
Email event occurs and the NR is reset with > 5 min between email event and reset
→ Should only receive one email (not within 5 minute debounce window)
Scenario 4 (changed behavior)
Email event occurs → NR is reset → another email event happens < 5 min later
→ Should only receive the latest email
Scenario 5 (changed behavior)
Multiple email events come in (all within 5 minutes of the one before it)
→ Should only receive the latest email
Scenario 6 (no change)
Two or more email events occur, but > 5 minutes have passed between them
→ Should receive both (or all) emails, since they are outside the debounce window
ahamood1 commentedon Jun 24, 2025
- instance = "namex-emailer-pending-send-queue-test"
- max_dispatches_per_second = 5
- max_concurrent_dispatches = 100
- max_attempts = 3
- max_retry_duration = "60s"
- min_backoff = "5s"
- max_backoff = "5s"
- max_doublings = 0
- sampling_ratio = 1.0
sa-apipermissions have been update to include:- "roles/cloudtasks.enqueuer"
- "roles/cloudtasks.viewer"
- "roles/cloudtasks.taskDeleter"
moraesfm commentedon Jun 26, 2025
FM-Approved1 - NR - OK
FM-Conditionally-Approved1 DR = NR 6236665 - OK
FM-Rejected1 - NR 2376837 - OK
FM-PAID1 = NR 7481454
FM-UPGRADE1 - OK