only trigger DVLA tasks if there is data to send

This commit is contained in:
Leo Hemsted
2017-09-22 14:06:31 +01:00
parent 04412fd314
commit cdc8acb49a

View File

@@ -316,12 +316,13 @@ def populate_monthly_billing():
@statsd(namespace="tasks") @statsd(namespace="tasks")
def run_letter_jobs(): def run_letter_jobs():
job_ids = dao_get_letter_job_ids_by_status(JOB_STATUS_READY_TO_SEND) job_ids = dao_get_letter_job_ids_by_status(JOB_STATUS_READY_TO_SEND)
notify_celery.send_task( if job_ids:
name=TaskNames.DVLA_JOBS, notify_celery.send_task(
args=(job_ids,), name=TaskNames.DVLA_JOBS,
queue=QueueNames.PROCESS_FTP args=(job_ids,),
) queue=QueueNames.PROCESS_FTP
current_app.logger.info("Queued {} ready letter job ids onto {}".format(len(job_ids), QueueNames.PROCESS_FTP)) )
current_app.logger.info("Queued {} ready letter job ids onto {}".format(len(job_ids), QueueNames.PROCESS_FTP))
@notify_celery.task(name="run-letter-notifications") @notify_celery.task(name="run-letter-notifications")
@@ -331,24 +332,25 @@ def run_letter_notifications():
notifications = dao_set_created_live_letter_api_notifications_to_pending() notifications = dao_set_created_live_letter_api_notifications_to_pending()
file_contents = create_dvla_file_contents_for_notifications(notifications) if notifications:
file_contents = create_dvla_file_contents_for_notifications(notifications)
file_location = '{}-dvla-notifications.txt'.format(current_time) file_location = '{}-dvla-notifications.txt'.format(current_time)
s3upload( s3upload(
filedata=file_contents + '\n', filedata=file_contents + '\n',
region=current_app.config['AWS_REGION'], region=current_app.config['AWS_REGION'],
bucket_name=current_app.config['DVLA_BUCKETS']['notification'], bucket_name=current_app.config['DVLA_BUCKETS']['notification'],
file_location=file_location file_location=file_location
) )
notify_celery.send_task( notify_celery.send_task(
name=TaskNames.DVLA_NOTIFICATIONS, name=TaskNames.DVLA_NOTIFICATIONS,
kwargs={'filename': file_location}, kwargs={'filename': file_location},
queue=QueueNames.PROCESS_FTP queue=QueueNames.PROCESS_FTP
) )
current_app.logger.info( current_app.logger.info(
"Queued {} ready letter api notifications onto {}".format( "Queued {} ready letter api notifications onto {}".format(
len(notifications), len(notifications),
QueueNames.PROCESS_FTP QueueNames.PROCESS_FTP
)
) )
)