-
Notifications
You must be signed in to change notification settings - Fork 32
[DO NOT MERGE] Fairer Queue implementation for individual queues #4692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/fair-queue-skeleton
Are you sure you want to change the base?
Changes from all commits
0c09d41
6e75174
c3a9edf
e5b366a
a63c51f
e70c98a
27e1805
63bc14e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
|
|
||
| import click | ||
| import flask | ||
| from app.celery.queue_utils import get_message_group_id_for_queue | ||
| from click_datetime import Datetime as click_dt | ||
| from dateutil import rrule | ||
| from flask import current_app, json | ||
|
|
@@ -292,7 +293,20 @@ def insert_inbound_numbers_from_file(file_name): | |
| ) | ||
| def replay_create_pdf_for_templated_letter(notification_id): | ||
| print(f"Create task to get_pdf_for_templated_letter for notification: {notification_id}") | ||
| get_pdf_for_templated_letter.apply_async([str(notification_id)], queue=QueueNames.CREATE_LETTERS_PDF) | ||
|
|
||
| queue_name = QueueNames.CREATE_LETTERS_PDF | ||
| message_group_kwargs = {} | ||
|
|
||
| if (current_app.config.get("ENABLE_SQS_FAIR_GROUPING", False)): | ||
| notification = Notification.query.filter(Notification.id == notification_id).one() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to do this (calling the database) - this is put in as an example |
||
| message_group_kwargs = get_message_group_id_for_queue( | ||
| queue_name=queue_name, | ||
| service_id=str(notification.service_id), | ||
| origin=notification.template.origin, | ||
| key_type=notification.key_type, | ||
| ) | ||
|
|
||
| get_pdf_for_templated_letter.apply_async([str(notification_id)], queue=queue_name, **message_group_kwargs) | ||
|
|
||
|
|
||
| @notify_command(name="recreate-pdf-for-precompiled-or-uploaded-letter") | ||
|
|
@@ -305,7 +319,19 @@ def replay_create_pdf_for_templated_letter(notification_id): | |
| ) | ||
| def recreate_pdf_for_precompiled_or_uploaded_letter(notification_id): | ||
| print(f"Call resanitise_pdf task for notification: {notification_id}") | ||
| resanitise_pdf.apply_async([str(notification_id)], queue=QueueNames.LETTERS) | ||
|
|
||
| queue_name = QueueNames.LETTERS | ||
| message_group_kwargs = {} | ||
| if (current_app.config.get("ENABLE_SQS_FAIR_GROUPING", False)): | ||
| notification = Notification.query.filter(Notification.id == notification_id).one() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to do this (calling the database) - this is put in as an example |
||
| message_group_kwargs = get_message_group_id_for_queue( | ||
| queue_name=queue_name, | ||
| service_id=str(notification.service_id), | ||
| origin=notification.template.origin, | ||
| key_type=notification.key_type, | ||
| ) | ||
|
|
||
| resanitise_pdf.apply_async([str(notification_id)], queue=queue_name, **message_group_kwargs) | ||
|
|
||
|
|
||
| def setup_commands(application): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
| from datetime import datetime | ||
|
|
||
| from flask import current_app | ||
| from app.celery.queue_utils import get_message_group_id_for_queue | ||
| from app.dao import notifications_dao | ||
| from gds_metrics import Histogram | ||
| from notifications_utils.clients import redis | ||
| from notifications_utils.formatters import strip_and_remove_obscure_whitespace | ||
|
|
@@ -232,8 +234,18 @@ def send_notification_to_queue_detached(key_type, notification_type, notificatio | |
| queue = QueueNames.CREATE_LETTERS_PDF | ||
| deliver_task = get_pdf_for_templated_letter | ||
|
|
||
| message_group_kwargs = {} | ||
| if (current_app.config.get("ENABLE_SQS_FAIR_GROUPING", False)): | ||
| notification = notifications_dao.get_notification_by_id(notification_id) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to do this (calling the database) - this is put in as an example |
||
| message_group_kwargs = get_message_group_id_for_queue( | ||
| queue_name=queue, | ||
| service_id=str(notification.service_id), | ||
| origin=notification.template.origin, | ||
| key_type=key_type, | ||
| ) | ||
|
|
||
| try: | ||
| deliver_task.apply_async([str(notification_id)], queue=queue) | ||
| deliver_task.apply_async([str(notification_id)], queue=queue, **message_group_kwargs) | ||
| except Exception: | ||
| dao_delete_notifications_by_id(notification_id) | ||
| raise | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This celery task was explicitly written so it didn't have to hit the database and this perfectly illustrates my objection to implementing group ids in this way, as mentioned here #4676 (comment) and in many other places.