Exemple #1
0
def run_update_user_agent_stats(script, opts, args):
    db = script.db_engines['app'].connect()
    redis = script.redis
    for key, count in redis.hgetall('ua').items():
        count = int(count)
        date, application_id, user_agent, ip = unpack_user_agent_stats_key(key)
        if not count:
            # the only way this could be 0 is if we already processed it and
            # nothing touched it since then, so it's safe to delete
            redis.hdel('ua', key)
        else:
            if script.config.cluster.role == 'master':
                update_user_agent_stats(db, application_id, date, user_agent, ip, count)
            else:
                call_internal_api(script.config, 'update_user_agent_stats',
                    application_id=application_id, date=date,
                    user_agent=user_agent, ip=ip, count=count)
            redis.hincrby('ua', key, -count)
def main(script, opts, args):
    db = script.engine.connect()
    redis = script.redis
    for key, count in redis.hgetall('ua').iteritems():
        count = int(count)
        date, application_id, user_agent, ip = unpack_user_agent_stats_key(key)
        if not count:
            # the only way this could be 0 is if we already processed it and
            # nothing touched it since then, so it's safe to delete
            redis.hdel('ua', key)
        else:
            if script.config.cluster.role == 'master':
                update_user_agent_stats(db, application_id, date, user_agent, ip, count)
            else:
                call_internal_api(script.config, 'update_user_agent_stats',
                    application_id=application_id, date=date,
                    user_agent=user_agent, ip=ip, count=count)
            redis.hincrby('ua', key, -count)
def main(script, opts, args):
    db = script.engine.connect()
    redis = script.redis
    for key, count in redis.hgetall('lookups').iteritems():
        count = int(count)
        date, hour, application_id, type = key.split(':')
        if not count:
            # the only way this could be 0 is if we already processed it and
            # nothing touched it since then, so it's safe to delete
            redis.hdel('lookups', key)
        else:
            if script.config.cluster.role == 'master':
                update_lookup_stats(db, application_id, date, hour, type, count)
            else:
                call_internal_api(script.config, 'update_lookup_stats',
                    application_id=application_id, date=date, hour=hour,
                    type=type, count=count)
            redis.hincrby('lookups', key, -count)
Exemple #4
0
def main(script, opts, args):
    db = script.engine.connect()
    redis = script.redis
    for key, count in redis.hgetall('lookups').iteritems():
        count = int(count)
        date, hour, application_id, type = key.split(':')
        if not count:
            # the only way this could be 0 is if we already processed it and
            # nothing touched it since then, so it's safe to delete
            redis.hdel('lookups', key)
        else:
            if script.config.cluster.role == 'master':
                update_lookup_stats(db, application_id, date, hour, type, count)
            else:
                call_internal_api(script.config, 'update_lookup_stats',
                    application_id=application_id, date=date, hour=hour,
                    type=type, count=count)
                time.sleep(0.5)
            redis.hincrby('lookups', key, -count)