mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-13 08:42:21 -05:00
make create_nightly_notification_status_for_day take notification_type
the nightly task won't be affected, it'll just trigger three times more sub-tasks. this doesn't need to be a two-part deploy because we only trigger this overnight, so as long as the deploy completes in daytime we don't need to worry about celery task signatures
This commit is contained in:
@@ -12,6 +12,11 @@ from app.dao.fact_billing_dao import (
|
||||
update_fact_billing
|
||||
)
|
||||
from app.dao.fact_notification_status_dao import fetch_notification_status_for_day, update_fact_notification_status
|
||||
from app.models import (
|
||||
SMS_TYPE,
|
||||
EMAIL_TYPE,
|
||||
LETTER_TYPE,
|
||||
)
|
||||
|
||||
|
||||
@notify_celery.task(name="create-nightly-billing")
|
||||
@@ -72,30 +77,31 @@ def create_nightly_notification_status(day_start=None):
|
||||
day_start = datetime.strptime(day_start, "%Y-%m-%d").date()
|
||||
for i in range(0, 4):
|
||||
process_day = day_start - timedelta(days=i)
|
||||
|
||||
create_nightly_notification_status_for_day.apply_async(
|
||||
kwargs={'process_day': process_day.isoformat()},
|
||||
queue=QueueNames.REPORTING
|
||||
)
|
||||
for notification_type in [SMS_TYPE, EMAIL_TYPE, LETTER_TYPE]:
|
||||
create_nightly_notification_status_for_day.apply_async(
|
||||
kwargs={'process_day': process_day.isoformat(), 'notification_type': notification_type},
|
||||
queue=QueueNames.REPORTING
|
||||
)
|
||||
|
||||
|
||||
@notify_celery.task(name="create-nightly-notification-status-for-day")
|
||||
@statsd(namespace="tasks")
|
||||
def create_nightly_notification_status_for_day(process_day):
|
||||
def create_nightly_notification_status_for_day(process_day, notification_type):
|
||||
process_day = datetime.strptime(process_day, "%Y-%m-%d").date()
|
||||
|
||||
start = datetime.utcnow()
|
||||
transit_data = fetch_notification_status_for_day(process_day=process_day)
|
||||
transit_data = fetch_notification_status_for_day(process_day=process_day, notification_type=notification_type)
|
||||
end = datetime.utcnow()
|
||||
current_app.logger.info('create-nightly-notification-status-for-day {} fetched in {} seconds'.format(
|
||||
current_app.logger.info('create-nightly-notification-status-for-day {} type {} fetched in {} seconds'.format(
|
||||
process_day,
|
||||
notification_type,
|
||||
(end - start).seconds)
|
||||
)
|
||||
|
||||
update_fact_notification_status(transit_data, process_day)
|
||||
update_fact_notification_status(transit_data, process_day, notification_type)
|
||||
|
||||
current_app.logger.info(
|
||||
"create-nightly-notification-status-for-day task complete: {} rows updated for day: {}".format(
|
||||
len(transit_data), process_day
|
||||
"create-nightly-notification-status-for-day task complete: {} rows updated for type {} for day: {}".format(
|
||||
len(transit_data), process_day, notification_type
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user