mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
Add docs/code comments for message send flow
This commit is contained in:
@@ -91,6 +91,13 @@ def check_sms_delivery_receipt(self, message_id, notification_id, sent_at):
|
||||
bind=True, name="deliver_sms", max_retries=48, default_retry_delay=300
|
||||
)
|
||||
def deliver_sms(self, notification_id):
|
||||
'''
|
||||
This logic will branch off to the final step in delivering
|
||||
the notification to sns.
|
||||
Logic is in place for delivery receipts.
|
||||
Additional logic to help devs output authentication code to
|
||||
terminal.
|
||||
'''
|
||||
try:
|
||||
current_app.logger.info(
|
||||
"Start sending SMS for notification id: {}".format(notification_id)
|
||||
@@ -108,7 +115,7 @@ def deliver_sms(self, notification_id):
|
||||
current_app.logger.warning(
|
||||
ansi_green + f"AUTHENTICATION CODE: {notification.content}" + ansi_reset
|
||||
)
|
||||
|
||||
# Code branches off to send_to_providers.py
|
||||
message_id = send_to_providers.send_sms_to_provider(notification)
|
||||
# We have to put it in UTC. For other timezones, the delay
|
||||
# will be ignored and it will fire immediately (although this probably only affects developer testing)
|
||||
|
||||
@@ -31,6 +31,10 @@ from app.v2.errors import TotalRequestsError
|
||||
|
||||
@notify_celery.task(name="process-job")
|
||||
def process_job(job_id, sender_id=None):
|
||||
'''
|
||||
We update job status, get the csv data from s3 and begin processing
|
||||
csv rows.
|
||||
'''
|
||||
start = datetime.utcnow()
|
||||
job = dao_get_job_by_id(job_id)
|
||||
current_app.logger.info(
|
||||
@@ -74,6 +78,7 @@ def process_job(job_id, sender_id=None):
|
||||
for row in recipient_csv.get_rows():
|
||||
process_row(row, template, job, service, sender_id=sender_id)
|
||||
|
||||
# End point/Exit point for message send flow.
|
||||
job_complete(job, start=start)
|
||||
|
||||
|
||||
@@ -109,6 +114,10 @@ def get_recipient_csv_and_template_and_sender_id(job):
|
||||
|
||||
|
||||
def process_row(row, template, job, service, sender_id=None):
|
||||
'''
|
||||
The process will branch off based on notification type,
|
||||
sms or email.
|
||||
'''
|
||||
template_type = template.template_type
|
||||
encrypted = encryption.encrypt(
|
||||
{
|
||||
@@ -121,6 +130,8 @@ def process_row(row, template, job, service, sender_id=None):
|
||||
}
|
||||
)
|
||||
|
||||
# Both save_sms and save_email have the same general
|
||||
# persist logic.
|
||||
send_fns = {NotificationType.SMS: save_sms, NotificationType.EMAIL: save_email}
|
||||
|
||||
send_fn = send_fns[template_type]
|
||||
@@ -130,6 +141,7 @@ def process_row(row, template, job, service, sender_id=None):
|
||||
task_kwargs["sender_id"] = sender_id
|
||||
|
||||
notification_id = create_uuid()
|
||||
# Kick-off persisting notification in save_sms/save_email.
|
||||
send_fn.apply_async(
|
||||
(
|
||||
str(service.id),
|
||||
@@ -163,7 +175,14 @@ def __total_sending_limits_for_job_exceeded(service, job, job_id):
|
||||
|
||||
@notify_celery.task(bind=True, name="save-sms", max_retries=5, default_retry_delay=300)
|
||||
def save_sms(self, service_id, notification_id, encrypted_notification, sender_id=None):
|
||||
'''
|
||||
We are persisting the notification to the db here and
|
||||
placing notification in queue to send to sns.
|
||||
'''
|
||||
notification = encryption.decrypt(encrypted_notification)
|
||||
# SerialisedService and SerialisedTemplate classes are
|
||||
# used here to grab the same service and template from the cache
|
||||
# to improve performance.
|
||||
service = SerialisedService.from_id(service_id)
|
||||
template = SerialisedTemplate.from_id_and_service_id(
|
||||
notification["template"],
|
||||
@@ -177,7 +196,8 @@ def save_sms(self, service_id, notification_id, encrypted_notification, sender_i
|
||||
).sms_sender
|
||||
else:
|
||||
reply_to_text = template.reply_to_text
|
||||
|
||||
# Return False when trial mode services try sending notifications
|
||||
# to non-team and non-simulated recipients.
|
||||
if not service_allowed_to_send_to(notification["to"], service, KeyType.NORMAL):
|
||||
current_app.logger.debug(
|
||||
"SMS {} failed as restricted service".format(notification_id)
|
||||
@@ -208,6 +228,7 @@ def save_sms(self, service_id, notification_id, encrypted_notification, sender_i
|
||||
reply_to_text=reply_to_text,
|
||||
)
|
||||
|
||||
# Kick off sns process in provider_tasks.py
|
||||
provider_tasks.deliver_sms.apply_async(
|
||||
[str(saved_notification.id)], queue=QueueNames.SEND_SMS
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user