(rid)
return results
Lookup a reaction via either rethinkdb or redis
Lookup a reaction via either rethinkdb or redis
Lookup a reaction via either rethinkdb or redis
def getReaction(rid):
    ''' Lookup a reaction via either rethinkdb or redis '''
    # Pull from redis first
    cache = lookupRedis("reaction", rid)
    # Resolve issues form race condition during editing of reactions
    if "lastrun" in cache:
        if cache['lastrun'] is None or cache['lastrun'] is "None":
            # Reset lastrun to 0 if it is not present or set to None
            cache['lastrun'] = 0
    else:
        cache['lastrun'] = 0

    # Pull from RethinkDB second
    try:
        results = r.table('reactions').get(rid).run(rdb_server)
        if results['lastrun'] is None:
            results['lastrun'] = 0
        results['cacheonly'] = False
        if int(cache['trigger']) > results['trigger']:
            results['trigger'] = int(cache['trigger'])
        if float(cache['lastrun']) > float(results['lastrun']):
            results['lastrun'] = float(cache['lastrun'])
        if "encrypted" in results:
            if results['encrypted'] is True:
                crypto = Fernet(config['crypto_key'])
                results['data'] = json.loads(crypto.decrypt(bytes(results['data'])))
    except (RqlDriverError, RqlRuntimeError, socket.error) as e:
        results = cache
        results['cacheonly'] = True
        logger.critical("RethinkDB is unaccessible, reaction %s was pulled from cache" % rid)
        logger.critical("RethinkDB Error: %s" % e.message)
    return results
def getReaction ( rid ) : # Pull from redis first cache = lookupRedis ( "reaction" , rid ) # Resolve issues form race condition during editing of reactions if "lastrun" in cache : if cache [ 'lastrun' ] is None or cache [ 'lastrun' ] is "None" : # Reset lastrun to 0 if it is not present or set to None cache [ 'lastrun' ] = 0 else : cache [ 'lastrun' ] = 0 # Pull from RethinkDB second try : results = r . table ( 'reactions' ) . get ( rid ) . run ( rdb_server ) if results [ 'lastrun' ] is None : results [ 'lastrun' ] = 0 results [ 'cacheonly' ] = False if int ( cache [ 'trigger' ] ) > results [ 'trigger' ] : results [ 'trigger' ] = int ( cache [ 'trigger' ] ) if float ( cache [ 'lastrun' ] ) > float ( results [ 'lastrun' ] ) : results [ 'lastrun' ] = float ( cache [ 'lastrun' ] ) if "encrypted" in results : if results [ 'encrypted' ] is True : crypto = Fernet ( config [ 'crypto_key' ] ) results [ 'data' ] = json . loads ( crypto . decrypt ( bytes ( results [ 'data' ] ) ) ) except ( RqlDriverError , RqlRuntimeError , socket . error ) as e : results = cache results [ 'cacheonly' ] = True logger . critical ( "RethinkDB is unaccessible, reaction %s was pulled from cache" % rid ) logger . critical ( "RethinkDB Error: %s" % e . message ) return results