in amazon_polly_async_batch/responseprocessor.py [0:0]
def process_completed_task(task_id, uri):
"""
Given a completed Polly task -- meaning that Polly could synthesize the text into speech, and that the output file
is in S3 ready to be picked up -- renames the file to be the requested one and updates the DynamoDb record for
the task with the status and completion time. Increments the success count on the set record.
:param task_id: the Polly task ID
:param uri: the path to the completed audio file
"""
logger.debug('Successfully processed task {}; setting status to {}'.format(task_id, 'Task completed'))
record = dynamo.TaskTable(TASK_TABLE).get_task(task_id)
# Rename the generated file so it's what was specified in the config file
prefix = 's3://{}/'.format(WORK_BUCKET)
source = uri.replace(prefix, '') if uri.startswith(prefix) else uri
target = record['outputKey']['S']
logger.debug('Renaming generated Polly file {} to {}'.format(source, target))
s3.copy_object(Bucket=WORK_BUCKET,
CopySource={'Bucket': WORK_BUCKET, 'Key': source},
Key=target)
s3.delete_object(Bucket=WORK_BUCKET, Key=source)
# Update the record in the tasks table
record['message'] = {'S': 'Task completed'}
update_task_and_set_table(record, True)