import traceback from pymongo import UpdateOne 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: msg = traceback.format_exc() ddsend_msg(f'{self.game_name}.{source_coll}字段异常 {msg}') logger.error(repr(e)) 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'])