コード例 #1
0
ファイル: internal.py プロジェクト: lessc0de/acoustid-server
 def _handle_internal(self, params):
     if self.cluster.role != 'master':
         logger.warning('Trying to call update_user_agent_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_user_agent_stats(self.conn, params.application_id, params.date,
                                 params.user_agent, params.ip, params.count)
     return {}
コード例 #2
0
ファイル: internal.py プロジェクト: ncarkaci/acoustid-server
 def _handle_internal(self, params):
     if self.cluster.role != 'master':
         logger.warning('Trying to call update_user_agent_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_user_agent_stats(self.conn, params.application_id, params.date,
                                 params.user_agent, params.ip, params.count)
     return {}
コード例 #3
0
 def _handle_internal(self, params):
     if self.ctx.config.cluster.role != 'master':
         logger.warning(
             'Trying to call update_user_agent_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_user_agent_stats(app_db, params.application_id, params.date,
                             params.user_agent, params.ip, params.count)
     self.ctx.db.session.commit()
     return {}
コード例 #4
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)
コード例 #5
0
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)