mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
Fix 0 billable units on provider callback
We occasionally get an SMS with 0 `billable_units` if the `delivery-sender-worker` is stopped in the middle of processing a notification - we have to fix these manually. This change checks the billable units when we get the response from our SMS provider and sets the correct billable units if it's 0.
This commit is contained in:
@@ -2,6 +2,7 @@ import uuid
|
||||
|
||||
from datetime import datetime
|
||||
from flask import current_app
|
||||
from notifications_utils.template import SMSMessageTemplate
|
||||
|
||||
from app import statsd_client
|
||||
from app.clients import ClientException
|
||||
@@ -15,6 +16,7 @@ from app.celery.service_callback_tasks import (
|
||||
from app.config import QueueNames
|
||||
from app.dao.notifications_dao import dao_update_notification
|
||||
from app.dao.service_callback_api_dao import get_service_delivery_status_callback_api_for_service
|
||||
from app.dao.templates_dao import dao_get_template_by_id
|
||||
from app.models import NOTIFICATION_PENDING
|
||||
|
||||
sms_response_mapper = {
|
||||
@@ -92,6 +94,19 @@ def _process_for_status(notification_status, client_name, provider_reference):
|
||||
notification.sent_at
|
||||
)
|
||||
|
||||
if notification.billable_units == 0:
|
||||
service = notification.service
|
||||
template_model = dao_get_template_by_id(notification.template_id, notification.template_version)
|
||||
|
||||
template = SMSMessageTemplate(
|
||||
template_model.__dict__,
|
||||
values=notification.personalisation,
|
||||
prefix=service.name,
|
||||
show_prefix=service.prefix_sms,
|
||||
)
|
||||
notification.billable_units = template.fragment_count
|
||||
notifications_dao.dao_update_notification(notification)
|
||||
|
||||
if notification_status != NOTIFICATION_PENDING:
|
||||
service_callback_api = get_service_delivery_status_callback_api_for_service(service_id=notification.service_id)
|
||||
# queue callback task only if the service_callback_api exists
|
||||
|
||||
Reference in New Issue
Block a user