code review feedback

This commit is contained in:
Kenneth Kehl
2024-01-08 14:31:28 -08:00
parent a5f78224b2
commit 726e0b15fa
4 changed files with 19 additions and 10 deletions

View File

@@ -1,3 +1,5 @@
import re
import botocore
from boto3 import Session
from expiringdict import ExpiringDict
@@ -8,7 +10,7 @@ from app.clients import AWS_CLIENT_CONFIG
FILE_LOCATION_STRUCTURE = "service-{}-notify/{}.csv"
JOBS = ExpiringDict(max_len=100, max_age_seconds=3600)
JOBS = ExpiringDict(max_len=100, max_age_seconds=3600 * 4)
def get_s3_file(bucket_name, file_location, access_key, secret_key, region):
@@ -91,11 +93,7 @@ def get_phone_number_from_s3(service_id, job_id, job_row_number):
correct_row = correct_row.split(",")
my_phone = correct_row[phone_index]
my_phone = my_phone.replace("(", "")
my_phone = my_phone.replace(")", "")
my_phone = my_phone.replace("-", "")
my_phone = my_phone.replace(" ", "")
my_phone = my_phone.replace("+", "")
my_phone = re.sub(r"[\+\s\(\)\-\.]*", "", my_phone)
return my_phone

View File

@@ -31,7 +31,7 @@ DELIVERY_RECEIPT_DELAY_IN_SECONDS = 120
@notify_celery.task(
bind=True,
name="check_sms_delivery_receipt",
max_retries=12,
max_retries=48,
default_retry_delay=300,
)
def check_sms_delivery_receipt(self, message_id, notification_id, sent_at):
@@ -92,7 +92,7 @@ def check_sms_delivery_receipt(self, message_id, notification_id, sent_at):
@notify_celery.task(
bind=True, name="deliver_sms", max_retries=12, default_retry_delay=300
bind=True, name="deliver_sms", max_retries=48, default_retry_delay=300
)
def deliver_sms(self, notification_id):
try:

View File

@@ -81,7 +81,12 @@ def send_sms_to_provider(notification):
if my_phone:
my_phone = my_phone.decode("utf-8")
if my_phone is None:
raise Exception("what happened to the phone number")
si = notification.service_id
ji = notification.job_id
jrn = notification.job_row_number
raise Exception(
f"The phone number for (Service ID: {si}; Job ID: {ji}; Job Row Number {jrn} was not found."
)
send_sms_kwargs = {
"to": my_phone,
"content": str(template),

View File

@@ -50,11 +50,17 @@ def test_get_s3_file_makes_correct_call(notify_api, mocker):
[
("phone number\r\n+15555555555", "aaa", 0, "15555555555"),
(
"day of week,favorite color,phone number\r\nmonday,green,15551111111\r\ntuesday,red,15552222222",
"day of week,favorite color,phone number\r\nmonday,green,1.555.111.1111\r\ntuesday,red,+1 (555) 222-2222",
"bbb",
1,
"15552222222",
),
(
"day of week,favorite color,phone number\r\nmonday,green,1.555.111.1111\r\ntuesday,red,+1 (555) 222-2222",
"ccc",
0,
"15551111111",
),
],
)
def test_get_phone_number_from_s3(