Exemple #1
0
 def _handle_internal(self, params):
     if self.cluster.role != 'master':
         logger.warning('Trying to call update_lookup_stats on %s server', self.cluster.role)
         raise errors.NotAllowedError()
     if self.cluster.secret != params.secret:
         logger.warning('Invalid cluster secret')
         raise errors.NotAllowedError()
     with self.conn.begin():
         update_lookup_stats(self.conn, params.application_id, params.date,
                             params.hour, params.type, params.count)
     return {}
Exemple #2
0
 def _handle_internal(self, params):
     if self.cluster.role != 'master':
         logger.warning('Trying to call update_lookup_stats on %s server', self.cluster.role)
         raise errors.NotAllowedError()
     if self.cluster.secret != params.secret:
         logger.warning('Invalid cluster secret')
         raise errors.NotAllowedError()
     with self.conn.begin():
         update_lookup_stats(self.conn, params.application_id, params.date,
                             params.hour, params.type, params.count)
     return {}
 def _handle_internal(self, params):
     if self.ctx.config.cluster.role != 'master':
         logger.warning('Trying to call update_lookup_stats on %s server',
                        self.ctx.config.cluster.role)
         raise errors.NotAllowedError()
     if self.ctx.config.cluster.secret != params.secret:
         logger.warning('Invalid cluster secret')
         raise errors.NotAllowedError()
     app_db = self.ctx.db.get_app_db()
     update_lookup_stats(app_db, params.application_id, params.date,
                         params.hour, params.type, params.count)
     self.ctx.db.session.commit()
     return {}
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 #5
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)