Return data to one of potentially many clustered cassandra nodes

def returner(ret):
    '''
    Return data to one of potentially many clustered cassandra nodes
    '''
    query = '''INSERT INTO {keyspace}.salt_returns (
                 jid, minion_id, fun, alter_time, full_ret, return, success
               ) VALUES (?, ?, ?, ?, ?, ?, ?)'''.format(keyspace=_get_keyspace())

    statement_arguments = ['{0}'.format(ret['jid']),
                           '{0}'.format(ret['id']),
                           '{0}'.format(ret['fun']),
                           int(time.time() * 1000),
                           salt.utils.json.dumps(ret).replace("'", "''"),
                           salt.utils.json.dumps(ret['return']).replace("'", "''"),
                           ret.get('success', False)]

    # cassandra_cql.cql_query may raise a CommandExecutionError
    try:
        __salt__['cassandra_cql.cql_query_with_prepare'](query,
                                                         'returner_return',
                                                         tuple(statement_arguments),
                                                         asynchronous=True)
    except CommandExecutionError:
        log.critical('Could not insert into salt_returns with Cassandra returner.')
        raise
    except Exception as e:
        log.critical('Unexpected error while inserting into salt_returns: %s', e)
        raise

    # Store the last function called by the minion
    # The data in salt.minions will be used by get_fun and get_minions
    query = '''INSERT INTO {keyspace}.minions (
                 minion_id, last_fun
               ) VALUES (?, ?)'''.format(keyspace=_get_keyspace())

    statement_arguments = ['{0}'.format(ret['id']), '{0}'.format(ret['fun'])]

    # cassandra_cql.cql_query may raise a CommandExecutionError
    try:
        __salt__['cassandra_cql.cql_query_with_prepare'](query,
                                                         'returner_minion',
                                                         tuple(statement_arguments),
                                                         asynchronous=True)
    except CommandExecutionError:
        log.critical('Could not store minion ID with Cassandra returner.')
        raise
    except Exception as e:
        log.critical(
            'Unexpected error while inserting minion ID into the minions '
            'table: %s', e
        )
        raise