排行榜工具线程化处理
This commit is contained in:
parent
0e548b4f07
commit
be6876015b
2
third_party/f7
vendored
2
third_party/f7
vendored
@ -1 +1 @@
|
||||
Subproject commit 07f321e38325d429b404331b027fc9da25587469
|
||||
Subproject commit 28da41e6f70c40f14f23fde87e9482df1f614544
|
@ -60,7 +60,7 @@ def _updateRank(r, channel, pass_list):
|
||||
pass_rank.append(pass_list[pass_index])
|
||||
r.set("game2003api:pass_rank_" + channel, json.dumps(pass_rank))
|
||||
|
||||
def dayReadMysqlData():
|
||||
def fullUpdateRank():
|
||||
mysql_conf = json.loads(open(CONFIG_DIR + '/rankserver.mysql.cluster.json', 'r').read())
|
||||
rank_hash = {}
|
||||
for conf in mysql_conf:
|
||||
@ -94,13 +94,13 @@ def dayReadMysqlData():
|
||||
_updateRank(r, channel, rank_hash[channel])
|
||||
|
||||
#每日定时读取mysql里的数据生成排行榜写入redis后php读取redis返回客户端显示
|
||||
def _dayReadMysqlData(rushtime):
|
||||
dayReadMysqlData()
|
||||
def _fullUpdateRank(rushtime):
|
||||
def done_callback():
|
||||
f7.timer.callAt(q7.getDaySeconds(time.time(), 1) + rushtime,
|
||||
lambda : _dayReadMysqlData(rushtime))
|
||||
lambda : _fullUpdateRank(rushtime))
|
||||
f7.app.createAsyncTask(done_callback, fullUpdateRank, ())
|
||||
|
||||
#每5分钟读取mysql里发生改变过的数据更新排行榜
|
||||
def _readMysqlData(rushtime):
|
||||
def incrementUpdateRank(rushtime):
|
||||
mysql_conf = json.loads(open(CONFIG_DIR + '/rankserver.mysql.cluster.json', 'r').read())
|
||||
r = _getRedis()
|
||||
rank_hash = {}
|
||||
@ -138,9 +138,12 @@ def _readMysqlData(rushtime):
|
||||
for channel in rank_hash:
|
||||
_updateRank(r, channel, rank_hash[channel])
|
||||
|
||||
#每5分钟读取mysql里发生改变过的数据更新排行榜
|
||||
def _incrementUpdateRank(rushtime):
|
||||
def done_callback():
|
||||
f7.timer.callLater(rushtime,
|
||||
lambda : _readMysqlData(rushtime)
|
||||
)
|
||||
lambda : _incrementUpdateRank(rushtime))
|
||||
f7.app.createAsyncTask(done_callback, incrementUpdateRank, ())
|
||||
|
||||
if __name__ == "__main__":
|
||||
f7.app.init('/data/logs/game2003_rankserver/logs')
|
||||
@ -150,11 +153,11 @@ if __name__ == "__main__":
|
||||
|
||||
conf['rushtime'] = 300
|
||||
f7.timer.callLater(conf['rushtime'],
|
||||
lambda : _readMysqlData(conf['rushtime']))
|
||||
lambda : _incrementUpdateRank(conf['rushtime']))
|
||||
|
||||
conf['day_rushtime'] = 5 * 3600
|
||||
f7.timer.callAt(q7.getDaySeconds(time.time(), 1) + conf['day_rushtime'],
|
||||
lambda : _dayReadMysqlData(conf['day_rushtime']))
|
||||
lambda : _fullUpdateRank(conf['day_rushtime']))
|
||||
|
||||
f7.app.listen(conf['listen_port'])
|
||||
f7.app.start()
|
||||
|
@ -17,7 +17,7 @@ import os
|
||||
import game2003rank
|
||||
|
||||
def _updateRank_cmd(debug_info):
|
||||
game2003rank.dayReadMysqlData()
|
||||
game2003rank.fullUpdateRank()
|
||||
|
||||
def _clearRank_cmd(debug_info):
|
||||
for conf in game2003rank.getRedisConf():
|
||||
|
Loading…
x
Reference in New Issue
Block a user