mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Merge branch 'master' of https://github.com/alphagov/notifications-api into add-mmg-inbound-sms-auth
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from flask import current_app
|
||||
import math
|
||||
from requests import (
|
||||
post as requests_post,
|
||||
RequestException
|
||||
@@ -9,7 +10,11 @@ from botocore.exceptions import ClientError as BotoClientError
|
||||
from app import notify_celery
|
||||
from app.aws import s3
|
||||
from app.config import QueueNames
|
||||
from app.dao.notifications_dao import get_notification_by_id, update_notification_status_by_id
|
||||
from app.dao.notifications_dao import (
|
||||
get_notification_by_id,
|
||||
update_notification_status_by_id,
|
||||
dao_update_notification
|
||||
)
|
||||
from app.statsd_decorators import statsd
|
||||
|
||||
|
||||
@@ -19,7 +24,7 @@ def create_letters_pdf(self, notification_id):
|
||||
try:
|
||||
notification = get_notification_by_id(notification_id, _raise=True)
|
||||
|
||||
pdf_data = get_letters_pdf(
|
||||
pdf_data, billable_units = get_letters_pdf(
|
||||
notification.template,
|
||||
contact_block=notification.reply_to_text,
|
||||
org_id=notification.service.dvla_organisation.id,
|
||||
@@ -28,6 +33,14 @@ def create_letters_pdf(self, notification_id):
|
||||
current_app.logger.info("PDF Letter {} reference {} created at {}, {} bytes".format(
|
||||
notification.id, notification.reference, notification.created_at, len(pdf_data)))
|
||||
s3.upload_letters_pdf(reference=notification.reference, crown=notification.service.crown, filedata=pdf_data)
|
||||
|
||||
notification.billable_units = billable_units
|
||||
dao_update_notification(notification)
|
||||
|
||||
current_app.logger.info(
|
||||
'Letter notification reference {reference}: billable units set to {billable_units}'.format(
|
||||
reference=str(notification.reference), billable_units=billable_units))
|
||||
|
||||
except (RequestException, BotoClientError):
|
||||
try:
|
||||
current_app.logger.exception(
|
||||
@@ -62,4 +75,7 @@ def get_letters_pdf(template, contact_block, org_id, values):
|
||||
)
|
||||
resp.raise_for_status()
|
||||
|
||||
return resp.content
|
||||
pages_per_sheet = 2
|
||||
billable_units = math.ceil(int(resp.headers.get("X-pdf-page-count", 0)) / pages_per_sheet)
|
||||
|
||||
return resp.content, billable_units
|
||||
|
||||
@@ -30,7 +30,7 @@ class QueueNames(object):
|
||||
RETRY = 'retry-tasks'
|
||||
NOTIFY = 'notify-internal-tasks'
|
||||
PROCESS_FTP = 'process-ftp-tasks'
|
||||
CREATE_LETTERS_PDF = 'create-letters-pdf'
|
||||
CREATE_LETTERS_PDF = 'create-letters-pdf-tasks'
|
||||
CALLBACKS = 'service-callbacks'
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user