mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
Ensure created_at stamp is correct
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
from datetime import timedelta
|
import os
|
||||||
|
from datetime import datetime, timedelta
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
@@ -29,6 +30,7 @@ from app.models import FactNotificationStatus, Notification, NotificationHistory
|
|||||||
from app.utils import (
|
from app.utils import (
|
||||||
escape_special_characters,
|
escape_special_characters,
|
||||||
get_midnight_in_utc,
|
get_midnight_in_utc,
|
||||||
|
hilite,
|
||||||
midnight_n_days_ago,
|
midnight_n_days_ago,
|
||||||
utc_now,
|
utc_now,
|
||||||
)
|
)
|
||||||
@@ -95,6 +97,27 @@ def dao_create_notification(notification):
|
|||||||
# notify-api-1454 insert only if it doesn't exist
|
# notify-api-1454 insert only if it doesn't exist
|
||||||
if not dao_notification_exists(notification.id):
|
if not dao_notification_exists(notification.id):
|
||||||
db.session.add(notification)
|
db.session.add(notification)
|
||||||
|
# There have been issues with invites expiring.
|
||||||
|
# Ensure the created at value is set and debug.
|
||||||
|
if notification.notification_type == "email":
|
||||||
|
orig_time = notification.created_at
|
||||||
|
|
||||||
|
now_time = utc_now()
|
||||||
|
print(hilite(f"original time: {orig_time} - {type(orig_time)} \n now time: {now_time} - {type(now_time)}"))
|
||||||
|
diff_time = now_time - datetime.strptime(orig_time, "%Y-%m-%D-%H-%M-%S")
|
||||||
|
current_app.logger.error(
|
||||||
|
f"dao_create_notification orig created at: {orig_time} and now created at: {now_time}"
|
||||||
|
)
|
||||||
|
if diff_time.total_seconds() > 300:
|
||||||
|
current_app.logger.error(
|
||||||
|
"Something is wrong with notification.created_at in email!"
|
||||||
|
)
|
||||||
|
if os.getenv("NOTIFY_ENVIRONMENT") not in ["test"]:
|
||||||
|
notification.created_at = now_time
|
||||||
|
dao_update_notification(notification)
|
||||||
|
current_app.logger.error(
|
||||||
|
f"Email notification created_at reset to {notification.created_at}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def country_records_delivery(phone_prefix):
|
def country_records_delivery(phone_prefix):
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ from app.notifications.process_notifications import (
|
|||||||
send_notification_to_queue,
|
send_notification_to_queue,
|
||||||
)
|
)
|
||||||
from app.schemas import invited_user_schema
|
from app.schemas import invited_user_schema
|
||||||
from app.utils import utc_now
|
from app.utils import hilite, utc_now
|
||||||
from notifications_utils.url_safe_token import check_token, generate_token
|
from notifications_utils.url_safe_token import check_token, generate_token
|
||||||
|
|
||||||
service_invite = Blueprint("service_invite", __name__)
|
service_invite = Blueprint("service_invite", __name__)
|
||||||
@@ -67,7 +67,7 @@ def _create_service_invite(invited_user, nonce, state):
|
|||||||
"service_name": invited_user.service.name,
|
"service_name": invited_user.service.name,
|
||||||
"url": url,
|
"url": url,
|
||||||
}
|
}
|
||||||
|
created_at = utc_now()
|
||||||
saved_notification = persist_notification(
|
saved_notification = persist_notification(
|
||||||
template_id=template.id,
|
template_id=template.id,
|
||||||
template_version=template.version,
|
template_version=template.version,
|
||||||
@@ -78,6 +78,10 @@ def _create_service_invite(invited_user, nonce, state):
|
|||||||
api_key_id=None,
|
api_key_id=None,
|
||||||
key_type=KeyType.NORMAL,
|
key_type=KeyType.NORMAL,
|
||||||
reply_to_text=invited_user.from_user.email_address,
|
reply_to_text=invited_user.from_user.email_address,
|
||||||
|
created_at=created_at,
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
hilite(f"saved notification created at time: {saved_notification.created_at}")
|
||||||
)
|
)
|
||||||
saved_notification.personalisation = personalisation
|
saved_notification.personalisation = personalisation
|
||||||
redis_store.set(
|
redis_store.set(
|
||||||
|
|||||||
Reference in New Issue
Block a user