mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-23 07:46:06 -04:00
reduce days to process from 10 to 4
to try and speed it up temporarily.
This commit is contained in:
@@ -18,13 +18,13 @@ from app.dao.fact_notification_status_dao import fetch_notification_status_for_d
|
|||||||
@statsd(namespace="tasks")
|
@statsd(namespace="tasks")
|
||||||
def create_nightly_billing(day_start=None):
|
def create_nightly_billing(day_start=None):
|
||||||
# day_start is a datetime.date() object. e.g.
|
# day_start is a datetime.date() object. e.g.
|
||||||
# up to 10 days of data counting back from day_start is consolidated
|
# up to 4 days of data counting back from day_start is consolidated
|
||||||
if day_start is None:
|
if day_start is None:
|
||||||
day_start = convert_utc_to_bst(datetime.utcnow()).date() - timedelta(days=1)
|
day_start = convert_utc_to_bst(datetime.utcnow()).date() - timedelta(days=1)
|
||||||
else:
|
else:
|
||||||
# When calling the task its a string in the format of "YYYY-MM-DD"
|
# When calling the task its a string in the format of "YYYY-MM-DD"
|
||||||
day_start = datetime.strptime(day_start, "%Y-%m-%d").date()
|
day_start = datetime.strptime(day_start, "%Y-%m-%d").date()
|
||||||
for i in range(0, 10):
|
for i in range(0, 4):
|
||||||
process_day = day_start - timedelta(days=i)
|
process_day = day_start - timedelta(days=i)
|
||||||
|
|
||||||
transit_data = fetch_billing_data_for_day(process_day=process_day)
|
transit_data = fetch_billing_data_for_day(process_day=process_day)
|
||||||
@@ -47,7 +47,7 @@ def create_nightly_notification_status(day_start=None):
|
|||||||
else:
|
else:
|
||||||
# When calling the task its a string in the format of "YYYY-MM-DD"
|
# When calling the task its a string in the format of "YYYY-MM-DD"
|
||||||
day_start = datetime.strptime(day_start, "%Y-%m-%d").date()
|
day_start = datetime.strptime(day_start, "%Y-%m-%d").date()
|
||||||
for i in range(0, 10):
|
for i in range(0, 4):
|
||||||
process_day = day_start - timedelta(days=i)
|
process_day = day_start - timedelta(days=i)
|
||||||
|
|
||||||
transit_data = fetch_notification_status_for_day(process_day=process_day)
|
transit_data = fetch_notification_status_for_day(process_day=process_day)
|
||||||
|
|||||||
@@ -444,14 +444,10 @@ def test_create_nightly_notification_status(notify_db_session):
|
|||||||
create_notification(template=first_template, status='delivered', created_at=datetime.utcnow() - timedelta(days=10))
|
create_notification(template=first_template, status='delivered', created_at=datetime.utcnow() - timedelta(days=10))
|
||||||
|
|
||||||
create_notification(template=second_template, status='temporary-failure')
|
create_notification(template=second_template, status='temporary-failure')
|
||||||
create_notification(template=second_template, status='temporary-failure',
|
create_notification(template=second_template, status='temporary-failure', created_at=datetime.utcnow() - timedelta(days=1)) # noqa
|
||||||
created_at=datetime.utcnow() - timedelta(days=1))
|
create_notification(template=second_template, status='temporary-failure', created_at=datetime.utcnow() - timedelta(days=2)) # noqa
|
||||||
create_notification(template=second_template, status='temporary-failure',
|
create_notification(template=second_template, status='temporary-failure', created_at=datetime.utcnow() - timedelta(days=10)) # noqa
|
||||||
created_at=datetime.utcnow() - timedelta(days=2))
|
create_notification(template=second_template, status='temporary-failure', created_at=datetime.utcnow() - timedelta(days=10)) # noqa
|
||||||
create_notification(template=second_template, status='temporary-failure',
|
|
||||||
created_at=datetime.utcnow() - timedelta(days=10))
|
|
||||||
create_notification(template=second_template, status='temporary-failure',
|
|
||||||
created_at=datetime.utcnow() - timedelta(days=10))
|
|
||||||
|
|
||||||
create_notification(template=third_template, status='created')
|
create_notification(template=third_template, status='created')
|
||||||
create_notification(template=third_template, status='created', created_at=datetime.utcnow() - timedelta(days=1))
|
create_notification(template=third_template, status='created', created_at=datetime.utcnow() - timedelta(days=1))
|
||||||
@@ -464,12 +460,14 @@ def test_create_nightly_notification_status(notify_db_session):
|
|||||||
create_nightly_notification_status()
|
create_nightly_notification_status()
|
||||||
new_data = FactNotificationStatus.query.order_by(
|
new_data = FactNotificationStatus.query.order_by(
|
||||||
FactNotificationStatus.bst_date,
|
FactNotificationStatus.bst_date,
|
||||||
FactNotificationStatus.notification_type
|
|
||||||
).all()
|
).all()
|
||||||
assert len(new_data) == 9
|
assert len(new_data) == 6 #
|
||||||
assert str(new_data[0].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=10), "%Y-%m-%d")
|
assert str(new_data[0].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=2), "%Y-%m-%d")
|
||||||
assert str(new_data[3].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=2), "%Y-%m-%d")
|
assert str(new_data[1].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=2), "%Y-%m-%d")
|
||||||
assert str(new_data[6].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=1), "%Y-%m-%d")
|
assert str(new_data[2].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=2), "%Y-%m-%d")
|
||||||
|
assert str(new_data[3].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=1), "%Y-%m-%d")
|
||||||
|
assert str(new_data[4].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=1), "%Y-%m-%d")
|
||||||
|
assert str(new_data[5].bst_date) == datetime.strftime(datetime.utcnow() - timedelta(days=1), "%Y-%m-%d")
|
||||||
|
|
||||||
|
|
||||||
# the job runs at 12:30am London time. 04/01 is in BST.
|
# the job runs at 12:30am London time. 04/01 is in BST.
|
||||||
|
|||||||
Reference in New Issue
Block a user