Skip to content

Commit

Permalink
incident fix maybe - stop updating api key last used (#2422)
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels authored Jan 22, 2025
1 parent a341728 commit 5c216bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
17 changes: 10 additions & 7 deletions app/notifications/process_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from app.celery import provider_tasks
from app.celery.letters_pdf_tasks import create_letters_pdf
from app.config import QueueNames
from app.dao.api_key_dao import update_last_used_api_key

# from app.dao.api_key_dao import update_last_used_api_key
from app.dao.notifications_dao import (
bulk_insert_notifications,
dao_create_notification,
Expand Down Expand Up @@ -134,8 +135,9 @@ def persist_notification(
if redis_store.get(redis.daily_limit_cache_key(service.id)):
redis_store.incr(redis.daily_limit_cache_key(service.id))
current_app.logger.info("{} {} created at {}".format(notification_type, notification_id, notification_created_at))
if api_key_id:
update_last_used_api_key(api_key_id, notification_created_at)
# try to fix an incident
# if api_key_id:
# update_last_used_api_key(api_key_id, notification_created_at)
return notification


Expand Down Expand Up @@ -301,7 +303,7 @@ def persist_notifications(notifications: List[VerifiedNotification]) -> List[Not
"""

lofnotifications = []
api_key_last_used = None
api_key_last_used = None # noqa: F841

for notification in notifications:
notification_created_at = notification.get("created_at") or datetime.utcnow()
Expand Down Expand Up @@ -365,9 +367,10 @@ def persist_notifications(notifications: List[VerifiedNotification]) -> List[Not
# We will only update the api key once
api_key_id = notification.get("api_key_id")
if api_key_id:
api_key_last_used = datetime.utcnow()
if api_key_last_used:
update_last_used_api_key(api_key_id, api_key_last_used)
api_key_last_used = datetime.utcnow() # noqa: F841
# try to fix an incident
# if api_key_last_used:
# update_last_used_api_key(api_key_id, api_key_last_used)
bulk_insert_notifications(lofnotifications)

return lofnotifications
Expand Down
14 changes: 8 additions & 6 deletions tests/app/notifications/test_process_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
from app.celery.utils import CeleryParams
from app.config import QueueNames
from app.dao.service_sms_sender_dao import dao_update_service_sms_sender
from app.models import (
from app.models import ( # ApiKey,
BULK,
NORMAL,
PRIORITY,
ApiKey,
Notification,
NotificationHistory,
ScheduledNotification,
Expand Down Expand Up @@ -411,8 +410,10 @@ def test_persist_notifications_list(self, sample_job, sample_api_key, notify_db_
assert persisted_notification[0].service == sample_job.service

# Test that the api key last_used_timestamp got updated
api_key = ApiKey.query.get(sample_api_key.id)
assert api_key.last_used_timestamp is not None

# incident fix - should revert this later
# api_key = ApiKey.query.get(sample_api_key.id)
# assert api_key.last_used_timestamp is not None

def test_persist_notifications_reply_to_text_is_original_value_if_sender_is_changed_later(
self, sample_template, sample_api_key, mocker
Expand Down Expand Up @@ -894,8 +895,9 @@ def test_transform_email_notification_stores_normalised_email(

assert persisted_notification.to == recipient
assert persisted_notification.normalised_to == expected_recipient_normalised
api_key = ApiKey.query.get(sample_api_key.id)
assert api_key.last_used_timestamp is not None
# incident fix - should revert this later
# api_key = ApiKey.query.get(sample_api_key.id)
# assert api_key.last_used_timestamp is not None


class TestDBSaveAndSendNotification:
Expand Down

0 comments on commit 5c216bb

Please sign in to comment.