Get and use sender_id from S3 metadata

The `save_email` and `save_sms` jobs were updated previously to take an
optional `sender_id` and to use this if it was available. This commit
now gets the `sender_id` from the S3 metadata if it exists and passes it
through the the tasks which save the job notifications. This means SMS
and emails sent through jobs can use a specified `sender_id` instead of
the default.
This commit is contained in:
Katie Smith
2018-11-05 16:16:48 +00:00
parent 8b5d48b113
commit d20e35d075
4 changed files with 117 additions and 3 deletions

View File

@@ -112,7 +112,7 @@ def process_job(job_id, sender_id=None):
template_type=template.template_type,
placeholders=template.placeholders
).rows:
process_row(row, template, job, service)
process_row(row, template, job, service, sender_id=sender_id)
job_complete(job, start=start)
@@ -134,7 +134,7 @@ def job_complete(job, resumed=False, start=None):
)
def process_row(row, template, job, service):
def process_row(row, template, job, service, sender_id=None):
template_type = template.template_type
encrypted = encryption.encrypt({
'template': str(template.id),
@@ -153,12 +153,17 @@ def process_row(row, template, job, service):
send_fn = send_fns[template_type]
task_kwargs = {}
if sender_id:
task_kwargs['sender_id'] = sender_id
send_fn.apply_async(
(
str(service.id),
create_uuid(),
encrypted,
),
task_kwargs,
queue=QueueNames.DATABASE if not service.research_mode else QueueNames.RESEARCH_MODE
)

View File

@@ -150,8 +150,10 @@ def create_job(service_id):
dao_create_job(job)
sender_id = data.get('sender_id')
if job.job_status == JOB_STATUS_PENDING:
process_job.apply_async([str(job.id)], queue=QueueNames.JOBS)
process_job.apply_async([str(job.id)], {'sender_id': sender_id}, queue=QueueNames.JOBS)
job_json = job_schema.dump(job).data
job_json['statistics'] = []