mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-20 22:39:43 -04:00
tz utility swap and many test updates
This commit is contained in:
@@ -6,7 +6,7 @@ from botocore.exceptions import ClientError as BotoClientError
|
||||
from flask import current_app
|
||||
from notifications_utils.letter_timings import LETTER_PROCESSING_DEADLINE
|
||||
from notifications_utils.postal_address import PostalAddress
|
||||
from notifications_utils.timezones import convert_utc_to_bst
|
||||
from notifications_utils.timezones import convert_utc_to_local_timezone
|
||||
|
||||
from app import encryption, notify_celery
|
||||
from app.aws import s3
|
||||
@@ -136,7 +136,7 @@ def collate_letter_pdfs_to_be_sent():
|
||||
that have not yet been sent.
|
||||
If run after midnight, it will collect up letters created before 5:30pm the day before.
|
||||
"""
|
||||
print_run_date = convert_utc_to_bst(datetime.utcnow())
|
||||
print_run_date = convert_utc_to_local_timezone(datetime.utcnow())
|
||||
if print_run_date.time() < LETTER_PROCESSING_DEADLINE:
|
||||
print_run_date = print_run_date - timedelta(days=1)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from flask import current_app
|
||||
from notifications_utils.clients.zendesk.zendesk_client import (
|
||||
NotifySupportTicket,
|
||||
)
|
||||
from notifications_utils.timezones import convert_utc_to_bst
|
||||
from notifications_utils.timezones import convert_utc_to_est
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
@@ -38,7 +38,7 @@ from app.models import (
|
||||
FactProcessingTime,
|
||||
Notification,
|
||||
)
|
||||
from app.utils import get_london_midnight_in_utc
|
||||
from app.utils import get_local_midnight_in_utc
|
||||
|
||||
|
||||
@notify_celery.task(name="remove_sms_email_jobs")
|
||||
@@ -90,8 +90,8 @@ def _delete_notifications_older_than_retention_by_type(notification_type):
|
||||
flexible_data_retention = fetch_service_data_retention_for_all_services_by_notification_type(notification_type)
|
||||
|
||||
for f in flexible_data_retention:
|
||||
day_to_delete_backwards_from = get_london_midnight_in_utc(
|
||||
convert_utc_to_bst(datetime.utcnow()).date() - timedelta(days=f.days_of_retention)
|
||||
day_to_delete_backwards_from = get_local_midnight_in_utc(
|
||||
convert_utc_to_est(datetime.utcnow()).date() - timedelta(days=f.days_of_retention)
|
||||
)
|
||||
|
||||
delete_notifications_for_service_and_type.apply_async(queue=QueueNames.REPORTING, kwargs={
|
||||
@@ -100,7 +100,7 @@ def _delete_notifications_older_than_retention_by_type(notification_type):
|
||||
'datetime_to_delete_before': day_to_delete_backwards_from
|
||||
})
|
||||
|
||||
seven_days_ago = get_london_midnight_in_utc(convert_utc_to_bst(datetime.utcnow()).date() - timedelta(days=7))
|
||||
seven_days_ago = get_local_midnight_in_utc(convert_utc_to_est(datetime.utcnow()).date() - timedelta(days=7))
|
||||
service_ids_with_data_retention = {x.service_id for x in flexible_data_retention}
|
||||
|
||||
# get a list of all service ids that we'll need to delete for. Typically that might only be 5% of services.
|
||||
@@ -289,20 +289,20 @@ def letter_raise_alert_if_no_ack_file_for_zip():
|
||||
|
||||
@notify_celery.task(name='save-daily-notification-processing-time')
|
||||
@cronitor("save-daily-notification-processing-time")
|
||||
def save_daily_notification_processing_time(bst_date=None):
|
||||
# bst_date is a string in the format of "YYYY-MM-DD"
|
||||
if bst_date is None:
|
||||
def save_daily_notification_processing_time(est_date=None):
|
||||
# est_date is a string in the format of "YYYY-MM-DD"
|
||||
if est_date is None:
|
||||
# if a date is not provided, we run against yesterdays data
|
||||
bst_date = (datetime.utcnow() - timedelta(days=1)).date()
|
||||
est_date = (datetime.utcnow() - timedelta(days=1)).date()
|
||||
else:
|
||||
bst_date = datetime.strptime(bst_date, "%Y-%m-%d").date()
|
||||
est_date = datetime.strptime(est_date, "%Y-%m-%d").date()
|
||||
|
||||
start_time = get_london_midnight_in_utc(bst_date)
|
||||
end_time = get_london_midnight_in_utc(bst_date + timedelta(days=1))
|
||||
start_time = get_local_midnight_in_utc(est_date)
|
||||
end_time = get_local_midnight_in_utc(est_date + timedelta(days=1))
|
||||
result = dao_get_notifications_processing_time_stats(start_time, end_time)
|
||||
insert_update_processing_time(
|
||||
FactProcessingTime(
|
||||
bst_date=bst_date,
|
||||
est_date=est_date,
|
||||
messages_total=result.messages_total,
|
||||
messages_within_10_secs=result.messages_within_10_secs
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from flask import current_app
|
||||
from notifications_utils.timezones import convert_utc_to_bst
|
||||
from notifications_utils.timezones import convert_utc_to_local_timezone
|
||||
|
||||
from app import notify_celery
|
||||
from app.config import QueueNames
|
||||
@@ -21,7 +21,7 @@ def create_nightly_billing(day_start=None):
|
||||
# day_start is a datetime.date() object. e.g.
|
||||
# up to 4 days of data counting back from day_start is consolidated
|
||||
if day_start is None:
|
||||
day_start = convert_utc_to_bst(datetime.utcnow()).date() - timedelta(days=1)
|
||||
day_start = convert_utc_to_local_timezone(datetime.utcnow()).date() - timedelta(days=1)
|
||||
else:
|
||||
# When calling the task its a string in the format of "YYYY-MM-DD"
|
||||
day_start = datetime.strptime(day_start, "%Y-%m-%d").date()
|
||||
@@ -87,7 +87,7 @@ def create_nightly_notification_status():
|
||||
mean the aggregated results are temporarily incorrect.
|
||||
"""
|
||||
|
||||
yesterday = convert_utc_to_bst(datetime.utcnow()).date() - timedelta(days=1)
|
||||
yesterday = convert_utc_to_local_timezone(datetime.utcnow()).date() - timedelta(days=1)
|
||||
|
||||
for notification_type in [SMS_TYPE, EMAIL_TYPE, LETTER_TYPE]:
|
||||
days = 10 if notification_type == LETTER_TYPE else 4
|
||||
|
||||
@@ -6,7 +6,7 @@ from flask import current_app
|
||||
from notifications_utils.insensitive_dict import InsensitiveDict
|
||||
from notifications_utils.postal_address import PostalAddress
|
||||
from notifications_utils.recipients import RecipientCSV
|
||||
from notifications_utils.timezones import convert_utc_to_bst
|
||||
from notifications_utils.timezones import convert_utc_to_local_timezone
|
||||
from requests import HTTPError, RequestException, request
|
||||
from sqlalchemy.exc import IntegrityError, SQLAlchemyError
|
||||
|
||||
@@ -487,7 +487,7 @@ def record_daily_sorted_counts(self, filename):
|
||||
)
|
||||
raise DVLAException(message)
|
||||
|
||||
billing_date = get_billing_date_in_bst_from_filename(filename)
|
||||
billing_date = get_billing_date_in_est_from_filename(filename)
|
||||
persist_daily_sorted_letter_counts(day=billing_date,
|
||||
file_name=filename,
|
||||
sorted_letter_counts=sorted_letter_counts)
|
||||
@@ -503,11 +503,11 @@ def parse_dvla_file(filename):
|
||||
raise DVLAException('DVLA response file: {} has an invalid format'.format(filename))
|
||||
|
||||
|
||||
def get_billing_date_in_bst_from_filename(filename):
|
||||
def get_billing_date_in_est_from_filename(filename):
|
||||
# exclude seconds from the date since we don't need it. We got a date ending in 60 second - which is not valid.
|
||||
datetime_string = filename.split('-')[1][:-2]
|
||||
datetime_obj = datetime.strptime(datetime_string, '%Y%m%d%H%M')
|
||||
return convert_utc_to_bst(datetime_obj).date()
|
||||
return convert_utc_to_local_timezone(datetime_obj).date()
|
||||
|
||||
|
||||
def persist_daily_sorted_letter_counts(day, file_name, sorted_letter_counts):
|
||||
|
||||
Reference in New Issue
Block a user