mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-23 15:56:45 -04:00
@@ -1,6 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import random
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
@@ -30,7 +29,8 @@ DELIVERY_RECEIPT_DELAY_IN_SECONDS = 30
|
|||||||
@notify_celery.task(
|
@notify_celery.task(
|
||||||
bind=True,
|
bind=True,
|
||||||
name="check_sms_delivery_receipt",
|
name="check_sms_delivery_receipt",
|
||||||
max_retries=72,
|
max_retries=48,
|
||||||
|
default_retry_delay=300,
|
||||||
)
|
)
|
||||||
def check_sms_delivery_receipt(self, message_id, notification_id, sent_at):
|
def check_sms_delivery_receipt(self, message_id, notification_id, sent_at):
|
||||||
"""
|
"""
|
||||||
@@ -62,10 +62,7 @@ def check_sms_delivery_receipt(self, message_id, notification_id, sent_at):
|
|||||||
carrier=carrier,
|
carrier=carrier,
|
||||||
provider_response=provider_response,
|
provider_response=provider_response,
|
||||||
)
|
)
|
||||||
base_delay = 3600 # one hour
|
raise self.retry(exc=ntfe)
|
||||||
jitter = random.randint(-1200, +1200) # nosec B311
|
|
||||||
retry_delay = base_delay + jitter
|
|
||||||
raise self.retry(countdown=retry_delay, exc=ntfe)
|
|
||||||
except ClientError as err:
|
except ClientError as err:
|
||||||
# Probably a ThrottlingException but could be something else
|
# Probably a ThrottlingException but could be something else
|
||||||
error_code = err.response["Error"]["Code"]
|
error_code = err.response["Error"]["Code"]
|
||||||
@@ -80,10 +77,7 @@ def check_sms_delivery_receipt(self, message_id, notification_id, sent_at):
|
|||||||
carrier=carrier,
|
carrier=carrier,
|
||||||
provider_response=provider_response,
|
provider_response=provider_response,
|
||||||
)
|
)
|
||||||
base_delay = 3600 # one hour
|
raise self.retry(exc=err)
|
||||||
jitter = random.randint(-1200, +1200) # nosec B311
|
|
||||||
retry_delay = base_delay + jitter
|
|
||||||
raise self.retry(countdown=retry_delay, exc=err)
|
|
||||||
|
|
||||||
if status == "success":
|
if status == "success":
|
||||||
status = NotificationStatus.DELIVERED
|
status = NotificationStatus.DELIVERED
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ class AwsCloudwatchClient(Client):
|
|||||||
message["delivery"].get("phoneCarrier", "Unknown Carrier"),
|
message["delivery"].get("phoneCarrier", "Unknown Carrier"),
|
||||||
)
|
)
|
||||||
|
|
||||||
if time_now > (created_at + timedelta(hours=73)):
|
if time_now > (created_at + timedelta(hours=3)):
|
||||||
# see app/models.py Notification. This message corresponds to "permanent-failure",
|
# see app/models.py Notification. This message corresponds to "permanent-failure",
|
||||||
# but we are copy/pasting here to avoid circular imports.
|
# but we are copy/pasting here to avoid circular imports.
|
||||||
return "failure", "Unable to find carrier response."
|
return "failure", "Unable to find carrier response."
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ class Config(object):
|
|||||||
current_minute = (datetime.now().minute + 1) % 60
|
current_minute = (datetime.now().minute + 1) % 60
|
||||||
|
|
||||||
CELERY = {
|
CELERY = {
|
||||||
"worker_max_tasks_per_child": 2000,
|
"worker_max_tasks_per_child": 500,
|
||||||
"broker_url": REDIS_URL,
|
"broker_url": REDIS_URL,
|
||||||
"broker_transport_options": {
|
"broker_transport_options": {
|
||||||
"visibility_timeout": 310,
|
"visibility_timeout": 310,
|
||||||
|
|||||||
28
migrations/versions/0413_add_message_id.py
Normal file
28
migrations/versions/0413_add_message_id.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
"""
|
||||||
|
|
||||||
|
Revision ID: 0413_add_message_id
|
||||||
|
Revises: 412_remove_priority
|
||||||
|
Create Date: 2023-12-11 11:35:22.873930
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
revision = "0413_add_message_id"
|
||||||
|
down_revision = "0412_remove_priority"
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.add_column("notifications", sa.Column("message_id", sa.Text))
|
||||||
|
op.create_index(
|
||||||
|
"ix_notifications_message_id",
|
||||||
|
"notifications",
|
||||||
|
["message_id"],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_index("ix_notifications_message_id", table_name="notifications")
|
||||||
|
op.drop_column("notifications", "message_id")
|
||||||
Reference in New Issue
Block a user