Refactor code to move business logic

- DVLA specific logic is now moved to letters_pdf_tasks
This commit is contained in:
Ken Tsang
2018-01-23 17:45:35 +00:00
parent 3355a29d01
commit edd030e5dd
4 changed files with 75 additions and 73 deletions

View File

@@ -5,10 +5,7 @@ from flask import current_app
import pytz
from boto3 import client, resource
from notifications_utils.s3 import s3upload as utils_s3upload
FILE_LOCATION_STRUCTURE = 'service-{}-notify/{}.csv'
LETTERS_PDF_FILE_LOCATION_STRUCTURE = '{folder}/NOTIFY.{reference}.{duplex}.{letter_class}.{colour}.{crown}.{date}.pdf'
def get_s3_file(bucket_name, file_location):
@@ -81,34 +78,6 @@ def remove_transformed_dvla_file(job_id):
return obj.delete()
def upload_letters_pdf(reference, crown, filedata):
now = datetime.utcnow()
print_datetime = now
if now.time() > current_app.config.get('LETTER_PROCESSING_DEADLINE'):
print_datetime = now + timedelta(days=1)
upload_file_name = LETTERS_PDF_FILE_LOCATION_STRUCTURE.format(
folder=print_datetime.date(),
reference=reference,
duplex="D",
letter_class="2",
colour="C",
crown="C" if crown else "N",
date=now.strftime('%Y%m%d%H%M%S')
).upper()
utils_s3upload(
filedata=filedata,
region=current_app.config['AWS_REGION'],
bucket_name=current_app.config['LETTERS_PDF_BUCKET_NAME'],
file_location=upload_file_name
)
current_app.logger.info("Uploading letters PDF {} to {}".format(
upload_file_name, current_app.config['LETTERS_PDF_BUCKET_NAME']))
def get_list_of_files_by_suffix(bucket_name, subfolder='', suffix='', last_modified=None):
s3_client = client('s3', current_app.config['AWS_REGION'])
paginator = s3_client.get_paginator('list_objects_v2')