def _dbox_sync_user(user, error): if error: try: raise error except: logger.exception("_dbox_sync_user error:") elif user: user = UserModel(**user) async_dbox = DropboxMixin() db = DB.instance() skt_opened = SocketPool.is_socket_opened(user.name) rst = yield gen.Task( _update_dbox_delta, db, async_dbox, user, skt_opened) if rst['status'] != ErrCode.ok: logger.warning("Dropbox periodic update for user {0}" "ended with status = {1}".format(user.name, rst['status'])) elif skt_opened: if 'updates' in rst and rst['updates']: SocketPool.notify_dbox_update(user.name, rst) else: logger.error("_dbox_sync_user user not found")
def dbox_periodic_update(): # TODO: fetch only needed fields cursor = DB.instance().accounts.find( {'dbox_access_token': {'$exists': True}}) cursor.each(callback=_dbox_sync_user)