mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Remove csv after process job is finished.
Fixed new tests.
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
from boto3 import resource
|
||||
|
||||
|
||||
def get_job_from_s3(bucket_name, job_id):
|
||||
def get_s3_job_object(bucket_name, job_id):
|
||||
s3 = resource('s3')
|
||||
key = s3.Object(bucket_name, '{}.csv'.format(job_id))
|
||||
return key.get()['Body'].read().decode('utf-8')
|
||||
return s3.Object(bucket_name, '{}.csv'.format(job_id))
|
||||
|
||||
|
||||
def get_job_from_s3(bucket_name, job_id):
|
||||
obj = get_s3_job_object(bucket_name, job_id)
|
||||
return obj.get()['Body'].read().decode('utf-8')
|
||||
|
||||
|
||||
def remove_job_from_s3(bucket_name, job_id):
|
||||
obj = get_s3_job_object(bucket_name, job_id)
|
||||
return obj.delete()
|
||||
|
||||
@@ -179,11 +179,19 @@ def process_job(job_id):
|
||||
job.processing_started = start
|
||||
job.processing_finished = finished
|
||||
dao_update_job(job)
|
||||
remove_job.apply_async((str(job_id),), queue='remove-job')
|
||||
current_app.logger.info(
|
||||
"Job {} created at {} started at {} finished at {}".format(job_id, job.created_at, start, finished)
|
||||
)
|
||||
|
||||
|
||||
@notify_celery.task(name="remove-job")
|
||||
def remove_job(job_id):
|
||||
job = dao_get_job_by_id(job_id)
|
||||
s3.remove_job_from_s3(job.bucket_name, job_id)
|
||||
current_app.logger.info("Job {} has been removed from s3.".format(job_id))
|
||||
|
||||
|
||||
@notify_celery.task(name="send-sms")
|
||||
def send_sms(service_id, notification_id, encrypted_notification, created_at):
|
||||
notification = encryption.decrypt(encrypted_notification)
|
||||
|
||||
Reference in New Issue
Block a user