mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-15 01:32:20 -05:00
allow you to pass in date to send perf stats
make it easier to replay sending data for a day if it failed the first time round
This commit is contained in:
@@ -150,11 +150,17 @@ def timeout_notifications():
|
||||
@notify_celery.task(name='send-daily-performance-platform-stats')
|
||||
@cronitor('send-daily-performance-platform-stats')
|
||||
@statsd(namespace="tasks")
|
||||
def send_daily_performance_platform_stats():
|
||||
def send_daily_performance_platform_stats(date=None):
|
||||
# date is a string in the format of "YYYY-MM-DD"
|
||||
if date is None:
|
||||
date = (datetime.utcnow() - timedelta(days=1)).date()
|
||||
else:
|
||||
date = datetime.strptime(date, "%Y-%m-%d").date()
|
||||
|
||||
if performance_platform_client.active:
|
||||
yesterday = datetime.utcnow() - timedelta(days=1)
|
||||
send_total_sent_notifications_to_performance_platform(bst_date=yesterday.date())
|
||||
processing_time.send_processing_time_to_performance_platform()
|
||||
|
||||
send_total_sent_notifications_to_performance_platform(bst_date=date)
|
||||
processing_time.send_processing_time_to_performance_platform(bst_date=date)
|
||||
|
||||
|
||||
def send_total_sent_notifications_to_performance_platform(bst_date):
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from app.utils import get_midnight_for_day_before, get_london_midnight_in_utc
|
||||
from app.utils import get_london_midnight_in_utc
|
||||
from app.dao.notifications_dao import dao_get_total_notifications_sent_per_day_for_performance_platform
|
||||
from app import performance_platform_client
|
||||
|
||||
|
||||
def send_processing_time_to_performance_platform():
|
||||
today = datetime.utcnow()
|
||||
start_time = get_midnight_for_day_before(today)
|
||||
end_time = get_london_midnight_in_utc(today)
|
||||
def send_processing_time_to_performance_platform(bst_date):
|
||||
start_time = get_london_midnight_in_utc(bst_date)
|
||||
end_time = get_london_midnight_in_utc(bst_date + timedelta(days=1))
|
||||
|
||||
send_processing_time_for_start_and_end(start_time, end_time)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime, timedelta, date
|
||||
|
||||
from freezegun import freeze_time
|
||||
|
||||
@@ -19,7 +19,7 @@ def test_send_processing_time_to_performance_platform_generates_correct_calls(mo
|
||||
create_notification(sample_template, created_at=created_at, sent_at=created_at + timedelta(seconds=15))
|
||||
create_notification(sample_template, created_at=datetime.utcnow() - timedelta(days=2))
|
||||
|
||||
send_processing_time_to_performance_platform()
|
||||
send_processing_time_to_performance_platform(date(2016, 10, 17))
|
||||
|
||||
send_mock.assert_any_call(datetime(2016, 10, 16, 23, 0), 'messages-total', 2)
|
||||
send_mock.assert_any_call(datetime(2016, 10, 16, 23, 0), 'messages-within-10-secs', 1)
|
||||
|
||||
Reference in New Issue
Block a user