Merge branch 'master' of https://github.com/alphagov/notifications-api into secrets-2FA

This commit is contained in:
venusbb
2017-06-13 10:52:59 +01:00
7 changed files with 105 additions and 7 deletions

View File

@@ -26,3 +26,10 @@ def remove_job_from_s3(service_id, job_id):
file_location = FILE_LOCATION_STRUCTURE.format(service_id, job_id)
obj = get_s3_object(bucket_name, file_location)
return obj.delete()
def remove_transformed_dvla_file(job_id):
bucket_name = current_app.config['DVLA_UPLOAD_BUCKET_NAME']
file_location = '{}-dvla-job.text'.format(job_id)
obj = get_s3_object(bucket_name, file_location)
return obj.delete()

View File

@@ -24,6 +24,7 @@ from app.dao.provider_details_dao import (
dao_toggle_sms_provider
)
from app.dao.users_dao import delete_codes_older_created_more_than_a_day_ago
from app.models import LETTER_TYPE
from app.notifications.process_notifications import send_notification_to_queue
from app.statsd_decorators import statsd
from app.celery.tasks import process_job
@@ -245,3 +246,12 @@ def delete_inbound_sms_older_than_seven_days():
except SQLAlchemyError as e:
current_app.logger.exception("Failed to delete inbound sms notifications")
raise
@notify_celery.task(name="remove_transformed_dvla_files")
@statsd(namespace="tasks")
def remove_transformed_dvla_files():
jobs = dao_get_jobs_older_than_limited_by(job_types=[LETTER_TYPE])
for job in jobs:
s3.remove_transformed_dvla_file(job.id)
current_app.logger.info("Transformed dvla file for job {} has been removed from s3.".format(job.id))

View File

@@ -204,6 +204,11 @@ class Config(object):
'options': {'queue': QueueNames.PERIODIC},
'kwargs': {'job_types': [LETTER_TYPE]}
},
'remove_transformed_dvla_files': {
'task': 'remove_transformed_dvla_files',
'schedule': crontab(minute=40, hour=4),
'options': {'queue': QueueNames.PERIODIC}
},
'timeout-job-statistics': {
'task': 'timeout-job-statistics',
'schedule': crontab(minute=0, hour=5),

View File

@@ -14,7 +14,7 @@ from app.v2.notifications.notification_schemas import get_notifications_request
def get_notification_by_id(id):
try:
casted_id = uuid.UUID(id)
except ValueError or AttributeError:
except (ValueError, AttributeError):
abort(404)
notification = notifications_dao.get_notification_with_personalisation(
authenticated_service.id, casted_id, key_type=None