def put_record_with_retry()

in source/update_ddb_from_stream/update_ddb_from_stream.py [0:0]


def put_record_with_retry(metric_type, event_time, record_data, merged_data, concurrency_token, attempt=0):
    print("Retry: {0} {1} {2}".format(metric_type, event_time, str(attempt)))
    if attempt > max_retry_attempts: return
    try:
        put_record(metric_type, event_time, merged_data, concurrency_token)
    except botocore.exceptions.ClientError as e:
        if e.response['Error']['Code'] == 'ConditionalCheckFailedException':
            sleep(randint(0,5))
            ddb_record = client.get_item(
                TableName = table_name,
                Key = {
                    'MetricType': {'S': metric_type},
                    'EventTime': {'S': event_time}
                },
                ConsistentRead = True
            )
            merged_data = merge_record_with_ddb(record_data, ddb_record)
            put_record_with_retry(metric_type, event_time, record_data, merged_data, concurrency_token, attempt+1)
        else: raise