mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
- If the task runs twice and the notification already exists ignore the primary key constraint.
- Remove prints - Add some more tests - Only allow the new method to run for emails
This commit is contained in:
@@ -18,7 +18,7 @@ from requests import (
|
||||
request,
|
||||
RequestException
|
||||
)
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.exc import SQLAlchemyError, IntegrityError
|
||||
|
||||
from app import (
|
||||
create_uuid,
|
||||
@@ -301,12 +301,11 @@ def save_api_email(self,
|
||||
|
||||
notification = encryption.decrypt(encrypted_notification)
|
||||
service = dao_fetch_service_by_id(notification['service_id'])
|
||||
print(notification)
|
||||
|
||||
try:
|
||||
current_app.logger.info(f"Persisting notification {notification['id']}")
|
||||
|
||||
saved_notification = persist_notification(
|
||||
persist_notification(
|
||||
notification_id=notification["id"],
|
||||
template_id=notification['template_id'],
|
||||
template_version=notification['template_version'],
|
||||
@@ -324,14 +323,16 @@ def save_api_email(self,
|
||||
)
|
||||
|
||||
q = QueueNames.SEND_EMAIL if not service.research_mode else QueueNames.RESEARCH_MODE
|
||||
print(q)
|
||||
provider_tasks.deliver_email.apply_async(
|
||||
[notification['id']],
|
||||
queue=q
|
||||
)
|
||||
current_app.logger.info(f"Email {notification['id']} has been persisted.")
|
||||
except IntegrityError:
|
||||
current_app.logger.info(f"Email {notification['id']} already exists.")
|
||||
|
||||
current_app.logger.debug("Email {} created at {}".format(saved_notification.id, saved_notification.created_at))
|
||||
except SQLAlchemyError as e:
|
||||
|
||||
try:
|
||||
self.retry(queue=QueueNames.RETRY, exc=e)
|
||||
except self.MaxRetriesExceededError:
|
||||
|
||||
@@ -31,7 +31,7 @@ class QueueNames(object):
|
||||
SMS_CALLBACKS = 'sms-callbacks'
|
||||
ANTIVIRUS = 'antivirus-tasks'
|
||||
SANITISE_LETTERS = 'sanitise-letter-tasks'
|
||||
SAVE_API_EMAIL = 'save-api-email'
|
||||
SAVE_API_EMAIL = 'save-api-email-tasks'
|
||||
|
||||
@staticmethod
|
||||
def all_queues():
|
||||
|
||||
@@ -203,7 +203,8 @@ def process_sms_or_email_notification(*, form, notification_type, api_key, templ
|
||||
simulated=simulated
|
||||
)
|
||||
|
||||
if str(service.id) == '539d63a1-701d-400d-ab11-f3ee2319d4d4' and api_key.key_type == KEY_TYPE_NORMAL:
|
||||
if str(service.id) == '539d63a1-701d-400d-ab11-f3ee2319d4d4' and api_key.key_type == KEY_TYPE_NORMAL \
|
||||
and notification_type == EMAIL_TYPE:
|
||||
# Put GOV.UK Email notifications onto a queue
|
||||
# To take the pressure off the db for API requests put the notification for our high volume service onto a queue
|
||||
# the task will then save the notification, then call send_notification_to_queue.
|
||||
|
||||
Reference in New Issue
Block a user