37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
import pymongo
|
|
from pymongo import UpdateOne
|
|
from pydantic import BaseModel, Field
|
|
|
|
from .task import Task
|
|
from utils import *
|
|
|
|
|
|
class SyncUser(Task):
|
|
"""
|
|
同步user info
|
|
"""
|
|
def cleaning(self, cursor_list):
|
|
for cursor in cursor_list: # type:dict
|
|
for source_coll, ts in cursor.items(): # type:str,dict
|
|
if ts['cursor_st'] == ts['cursor_et']:
|
|
continue
|
|
logger.info(f'开始处理{self.game_name} 处理 {source_coll} 游标 {ts}')
|
|
where = {
|
|
'_ut': {
|
|
'$gte': ts['cursor_st'],
|
|
'$lt': ts['cursor_et'],
|
|
}
|
|
}
|
|
bulk_data = []
|
|
for item in self.local_db[source_coll].find(where, {'_id': False}):
|
|
try:
|
|
bulk_data.append(
|
|
UpdateOne({'_game_role_id': item['_game_role_id']},
|
|
{'$set': item}, upsert=True))
|
|
except Exception as e:
|
|
logger.error(f'msg:{e}')
|
|
# pass
|
|
if bulk_data:
|
|
self.remote_db[self.dest_coll].bulk_write(bulk_data, ordered=False)
|
|
self.set_cursor(cursor_st=ts['cursor_st'], cursor_et=ts['cursor_et'])
|