mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-11 09:27:56 -04:00
- Added a scheduled task to create or update billing for the month, yesterday is used to calculate the start and end date for the month.
- The new task has not been added to the beat application yet. - Added an updated_at column to the monthly billing table, we may want to only calculate from the last updated date rather than the entire month.
This commit is contained in:
@@ -9,9 +9,17 @@ from sqlalchemy.exc import SQLAlchemyError
|
||||
from app.aws import s3
|
||||
from app import notify_celery
|
||||
from app import performance_platform_client
|
||||
from app.dao.date_util import get_month_start_end_date
|
||||
from app.dao.inbound_sms_dao import delete_inbound_sms_created_more_than_a_week_ago
|
||||
from app.dao.invited_user_dao import delete_invitations_created_more_than_two_days_ago
|
||||
from app.dao.jobs_dao import dao_set_scheduled_jobs_to_pending, dao_get_jobs_older_than_limited_by
|
||||
from app.dao.jobs_dao import (
|
||||
dao_set_scheduled_jobs_to_pending,
|
||||
dao_get_jobs_older_than_limited_by
|
||||
)
|
||||
from app.dao.monthly_billing_dao import (
|
||||
get_service_ids_that_need_sms_billing_populated,
|
||||
create_or_update_monthly_billing_sms
|
||||
)
|
||||
from app.dao.notifications_dao import (
|
||||
dao_timeout_notifications,
|
||||
is_delivery_slow_for_provider,
|
||||
@@ -281,3 +289,14 @@ def delete_dvla_response_files_older_than_seven_days():
|
||||
except SQLAlchemyError as e:
|
||||
current_app.logger.exception("Failed to delete dvla response files")
|
||||
raise
|
||||
|
||||
|
||||
@notify_celery.task(name="populate_monthly_billing")
|
||||
@statsd(namespace="tasks")
|
||||
def populate_monthly_billing():
|
||||
# for every service with billable units this month update billing totals for yesterday
|
||||
# this will overwrite the existing amount.
|
||||
yesterday = datetime.utcnow() - timedelta(days=1)
|
||||
start_date, end_date = get_month_start_end_date(yesterday)
|
||||
services = get_service_ids_that_need_sms_billing_populated(start_date, end_date=end_date)
|
||||
[create_or_update_monthly_billing_sms(service_id=s.service_id, billing_month=start_date) for s in services]
|
||||
|
||||
Reference in New Issue
Block a user