def tr(happeningid): model_mgr = ModelRequestMgr() happening = Happening.getByKeyForUpdate(happeningid) raidboss = BackendApi.get_raid(model_mgr, happening.id, happening_eventvalue=happening.event) BackendApi.tr_happening_end(model_mgr, happening, raidboss) model_mgr.write_all() return model_mgr
def handle(self, *args, **options): print '================================' print 'update_missed_happening' print '================================' # 有効期限. now = OSAUtil.get_now() limittime = now # レイド発生中で期限切れのハプニングを取得. happeninglist = Happening.fetchValues(['id'], { 'state': Defines.HappeningState.ACTIVE, 'etime__lte': limittime }, limit=30000, using=backup_db) def tr(happeningid): model_mgr = ModelRequestMgr() BackendApi.tr_happening_missed(model_mgr, happeningid) model_mgr.write_all() return model_mgr for happening in happeninglist: try: model_mgr = db_util.run_in_transaction(tr, happening.id) model_mgr.write_end() except CabaretError, err: if err.code == CabaretError.Code.ALREADY_RECEIVED: pass else: raise print 'update %d end' % happening.id
def handle(self, *args, **options): print '================================' print 'update_happeningend' print '================================' # 有効期限. now = OSAUtil.get_now() limittime = now - datetime.timedelta(seconds=600) # レイド発生中で期限切れのハプニングを取得. happeninglist = Happening.fetchValues(['id'], {'state':Defines.HappeningState.CLEAR, 'etime__lte':limittime}, limit=30000, using=backup_db) def tr(happeningid): model_mgr = ModelRequestMgr() happening = Happening.getByKeyForUpdate(happeningid) raidboss = BackendApi.get_raid(model_mgr, happening.id, happening_eventvalue=happening.event) BackendApi.tr_happening_end(model_mgr, happening, raidboss) model_mgr.write_all() return model_mgr for happening in happeninglist: try: model_mgr = db_util.run_in_transaction(tr, happening.id) model_mgr.write_end() except CabaretError, err: if err.code == CabaretError.Code.ALREADY_RECEIVED: pass else: raise print 'update %d end' % happening.id
def check(self): self.checkResponseStatus() # 進行情報があるかを確認. happening = Happening.getByKey(self.__happening.id) playerhappening = PlayerHappening.getByKey(self.__player0.id) if happening is None or happening.progress == 0: raise AppTestError(u'進行情報が保存されていない') # 報酬. resultlist = playerhappening.happening_result.get('result', None) if resultlist is None: raise AppTestError(u'結果が設定されていない') gold_add = 0 for result in resultlist: self.__player0.exp += result['exp_add'] gold_add += result['gold_add'] # お金確認. if happening.gold != gold_add: raise AppTestError(u'お金が正しくない') # 経験値. playerexp = PlayerExp.getByKey(self.__player0.id) if playerexp.exp != self.__player0.exp: raise AppTestError(u'お金が正しくない') # イベント設定されているか. eventlist = playerhappening.happening_result.get('event', None) if not eventlist: raise AppTestError(u'イベントが設定されていない') # レベルアップとスカウト完了のイベントが設定されているか. levelupevent = None completeevent = None for event in eventlist: if event.get_type() == Defines.ScoutEventType.LEVELUP: levelupevent = event elif event.get_type() == Defines.ScoutEventType.COMPLETE: completeevent = event if levelupevent is None: raise AppTestError(u'レベルアップイベントが設定されていない') elif completeevent is None: raise AppTestError(u'スカウト完了イベントが設定されていない') elif playerexp.level != levelupevent.level: raise AppTestError(u'レベルアップイベントに正しくレベルが設定されていない.%d vs %d' % (playerexp.level, levelupevent.level)) elif happening.mid != completeevent.scoutid: raise AppTestError(u'完了イベントに正しくハプニングIDが設定されていない.%d vs %d' % (happening.mid, completeevent.scoutid)) # レイド. raid = Raid.getByKey(self.__happening.id) if raid is None: raise AppTestError(u'レイドが発生していない.')
def putRaid(self, modellist, player, happeningmaster, raidmaster, etime, state=Defines.HappeningState.BOSS): """レイド. """ playerhappening = player.getModel(PlayerHappening) playerhappening.happening += 1 ins_id = Happening.makeID(playerhappening.id, playerhappening.happening) happening = Happening.makeInstance(ins_id) happening.oid = playerhappening.id happening.mid = happeningmaster.id happening.state = state happening.etime = etime happening.progress = happeningmaster.execution happening.gold = 0 happening.items = {} happening.level = 1 happening.hprate = random.randint(raidmaster.hprate_min, raidmaster.hprate_max) modellist.append(happening) if state in (Defines.HappeningState.BOSS, Defines.HappeningState.CLEAR, Defines.HappeningState.END, Defines.HappeningState.MISS): raid = Raid.makeInstance(happening.id) raid.oid = happening.oid raid.mid = raidmaster.id raid.level = happening.level raid.damage_record = {} raidboss = RaidBoss(raid, raidmaster) raid.hprate = happening.hprate if state in (Defines.HappeningState.CLEAR, Defines.HappeningState.END): raid.hp = 0 else: raid.hp = raidboss.get_maxhp() raidboss.addDamageRecord(happening.oid, 1) raidboss.refrectDamageRecord() modellist.append(raid) else: raidboss = None return HappeningRaidSet(HappeningSet(happening, happeningmaster), raidboss)
def handle(self, *args, **options): starttime = OSAUtil.get_now() print '================================' print 'delete_finished_happening' print '================================' # 有効期限. now = OSAUtil.get_now() limittime = now - datetime.timedelta(days=28, seconds=68400) def tr(happeninglist): model_mgr = ModelRequestMgr() idlist = [] for happening in happeninglist: BackendApi.tr_delete_happening(model_mgr, happening.id) idlist.append(happening.id) model_mgr.write_all() return model_mgr, idlist TIMELIMIT = 7100 LIMIT_PER_LOOP = 50 LOOP = 100000 / LIMIT_PER_LOOP del_num = 0 for _ in xrange(LOOP): # 終了したハプニングを取得. happeninglist = Happening.fetchValues(['id'], {'etime__lt': limittime}, limit=LIMIT_PER_LOOP, using=settings.DB_DEFAULT) if not happeninglist: break model_mgr, idlist = db_util.run_in_transaction(tr, happeninglist) model_mgr.write_end() del_num += 1 print 'delete %d end' % idlist time.sleep(0.1) diff = OSAUtil.get_now() - starttime sec = diff.days * 86400 + diff.seconds if TIMELIMIT <= sec: break print '================================' print 'all end..' print 'delete num = %d' % del_num diff = OSAUtil.get_now() - starttime sec = diff.days * 86400 + diff.seconds print 'time %d.%06d' % (sec, diff.microseconds)
def check(self): self.checkResponseStatus() # 進行情報があるかを確認. happening = Happening.getByKey(self.__happening.id) playerhappening = PlayerHappening.getByKey(self.__player0.id) if happening is None or happening.progress == 0: raise AppTestError(u'進行情報が保存されていない') # 報酬. resultlist = playerhappening.happening_result.get('result', None) if resultlist is None: raise AppTestError(u'結果が設定されていない') gold_add = 0 for result in resultlist: self.__player0.exp += result['exp_add'] gold_add += result['gold_add'] # お金確認. if happening.gold != gold_add: raise AppTestError(u'お金が正しくない') # 経験値. playerexp = PlayerExp.getByKey(self.__player0.id) if playerexp.exp != self.__player0.exp: raise AppTestError(u'お金が正しくない') # イベント設定されているか. eventlist = playerhappening.happening_result.get('event', None) if not eventlist: raise AppTestError(u'イベントが設定されていない') # アイテム獲得のイベントが設定されているか. targetevent = None for event in eventlist: if event.get_type() == Defines.ScoutEventType.GET_ITEM: targetevent = event if targetevent is None: raise AppTestError(u'アイテム獲得が設定されていない') elif targetevent.item != self.__itemmaster.id: raise AppTestError(u'イベントのアイテムIDが正しくない') # 報酬リストにアイテムが入っているか. if not happening.idDropped(Defines.ItemType.ITEM, self.__itemmaster.id): raise AppTestError(u'報酬リストにアイテムが設定されていない')
def check(self): self.checkResponseStatus() # 進行情報があるかを確認. happening = Happening.getByKey(self.__happening.id) playerhappening = PlayerHappening.getByKey(self.__player0.id) if happening is None: raise AppTestError(u'進行情報が保存されていない') # 報酬. resultlist = playerhappening.happening_result.get('result', None) if resultlist is None: raise AppTestError(u'結果が設定されていない') gold_add = 0 for result in resultlist: self.__player0.exp += result['exp_add'] gold_add += result['gold_add'] # お金確認. if happening.gold != gold_add: raise AppTestError(u'お金が正しくない') # 経験値. playerexp = PlayerExp.getByKey(self.__player0.id) if playerexp.exp != self.__player0.exp: raise AppTestError(u'お金が正しくない') # イベント設定されているか. eventlist = playerhappening.happening_result.get('event', None) if not eventlist: raise AppTestError(u'イベントが設定されていない') # イベント設定されているか. eventlist = playerhappening.happening_result.get('event', None) if not eventlist: raise AppTestError(u'イベントが設定されていない') # 体力不足のイベントが設定されているか. targetevent = None for event in eventlist: if event.get_type() == Defines.ScoutEventType.AP_NONE: targetevent = event if targetevent is None: raise AppTestError(u'体力不足イベントが設定されていない')
def check(self): self.checkResponseStatus() # 進行情報があるかを確認. happening = Happening.getByKey(self.__happening.id) playerhappening = PlayerHappening.getByKey(self.__player0.id) if happening is None or happening.progress == 0: raise AppTestError(u'進行情報が保存されていない') # 報酬. resultlist = playerhappening.happening_result.get('result', None) if resultlist is None: raise AppTestError(u'結果が設定されていない') gold_add = 0 for result in resultlist: self.__player0.exp += result['exp_add'] gold_add += result['gold_add'] # お金確認. if happening.gold != gold_add: raise AppTestError(u'お金が正しくない') # 経験値. playerexp = PlayerExp.getByKey(self.__player0.id) if playerexp.exp != self.__player0.exp: raise AppTestError(u'お金が正しくない') # イベント設定されているか. eventlist = playerhappening.happening_result.get('event', None) if not eventlist: raise AppTestError(u'イベントが設定されていない') # レベルアップのイベントが設定されているか. targetevent = None for event in eventlist: if event.get_type() == Defines.ScoutEventType.LEVELUP: targetevent = event if targetevent is None: raise AppTestError(u'レベルアップイベントが設定されていない') elif playerexp.level != targetevent.level: raise AppTestError(u'イベントに正しくレベルが設定されていない.%d vs %d' % (playerexp.level, targetevent.level))
def procDo(self, args): """書き込み. """ self.addloginfo('procDo') if settings_sub.IS_BENCH: v_player = self.getViewerPlayer() raidid = str(Happening.makeID(v_player.id, 101)) confirmkey = '' else: raidid = str(args.get(1, '')) confirmkey = urllib.unquote(args.get(2, '')) is_strong = self.request.get(Defines.URLQUERY_STRONG) == '1' model_mgr = self.getModelMgr() self.addloginfo('get args') # レイド情報を取得. raidboss = None if raidid.isdigit(): happeningraidset = BackendApi.get_happeningraidset( model_mgr, int(raidid)) if happeningraidset: raidboss = happeningraidset.raidboss self.addloginfo('get raidboss') if raidboss is None: raise CabaretError(u'超太客にを接客できません', CabaretError.Code.ILLEGAL_ARGS) # プレイヤー. v_player = self.getViewerPlayer() uid = v_player.id self.addloginfo('getViewerPlayer') # デッキ. deckcardlist = self.getDeckCardList() self.addloginfo('getDeckCardList') # 助っ人. friendcard = self.getSelectedFriendCard(raidboss.id, do_set_default=False) self.addloginfo('getSelectedFriendCard') # SHOWTIME. champagne = False eventvalue = happeningraidset.happening.happening.event raideventid = HappeningUtil.get_raideventid(eventvalue) score = 0 if raideventid: raideventmaster = BackendApi.get_current_raideventmaster( model_mgr, using=settings.DB_READONLY) raidmaster = raidboss.raideventraidmaster #raidhelp = RaidHelp.getValues(filters={'toid':uid, 'raidid':raidboss.id}) if uid == raidboss.raid.oid: score = BackendApi.get_raidevent_specialbonusscore( model_mgr, uid, raidmaster.specialcard, raidmaster.specialcard_treasure, deckcardlist, using=settings.DB_DEFAULT) else: score = BackendApi.get_raidevent_specialbonusscore( model_mgr, uid, raidmaster.specialcard, raidmaster.specialcard_treasure, deckcardlist, raidid=raidboss.raid.id, using=settings.DB_DEFAULT) if raideventmaster and raideventmaster.id == raideventid: champagnedata = BackendApi.get_raidevent_champagne( model_mgr, uid, using=settings.DB_READONLY) if champagnedata and champagnedata.isChampagneCall( raideventid): champagne = True scouteventid = HappeningUtil.get_scouteventid(eventvalue) if scouteventid: scouteventmaster = BackendApi.get_current_scouteventmaster( model_mgr, using=settings.DB_READONLY) if scouteventmaster and scouteventmaster.id == scouteventid: playdata = BackendApi.get_event_playdata( model_mgr, scouteventid, uid, using=settings.DB_READONLY) if playdata and playdata.is_lovetime(): champagne = True # 書き込み. try: model_mgr = db_util.run_in_transaction(self.tr_write, uid, raidboss.id, confirmkey, raidboss.master, deckcardlist, friendcard, is_strong, champagne, score) model_mgr.write_end() except CabaretError, err: if settings_sub.IS_LOCAL: raise elif err.code == CabaretError.Code.ALREADY_RECEIVED: # アニメーションにいけるはず. model_mgr = ModelRequestMgr() battleresult = BackendApi.get_raid_battleresult( model_mgr, v_player.id, using=settings.DB_DEFAULT) if battleresult.is_strong != is_strong: # 戻す. if raidboss.raid.oid == v_player.id: # 発見者. url = UrlMaker.happening() else: # 救援者. url = UrlMaker.raidhelpdetail(raidboss.raid.id) self.appRedirect(self.makeAppLinkUrlRedirect(url)) return elif err.code == CabaretError.Code.OVER_LIMIT: # 撃破済みか終了済み.結果に飛ばすか. if raidboss.raid.oid == v_player.id: # 発見者. url = UrlMaker.raidend(raidboss.id) else: # 救援者.終了しましたを出せるようになったので飛ばす. url = UrlMaker.raidhelpdetail(raidboss.raid.id) self.appRedirect(self.makeAppLinkUrlRedirect(url)) return else: raise
def handle(self, *args, **options): model_mgr = ModelRequestMgr() starttime = OSAUtil.get_now() print '================================' print 'delete_happening_all' print '================================' # クリア済みで受け取っていないハプニング. print '================================' print 'check raid:start' # クリア済みのレイドを全て終了させる. filters = {'state__in':[Defines.HappeningState.BOSS, Defines.HappeningState.CLEAR]} num = Happening.count(filters) print 'happenings %d' % num # メンテナンス確認. appconfig = BackendApi.get_appconfig(model_mgr) if not appconfig.is_maintenance(): print u'メンテナンスモードにしてください' return print 'check maintenance...OK' offset = 0 LIMIT = 200 def tr_clear(happeningid): model_mgr = ModelRequestMgr() happening = Happening.getByKeyForUpdate(happeningid) raidboss = BackendApi.get_raid(model_mgr, happeningid) BackendApi.tr_happening_end(model_mgr, happening, raidboss) model_mgr.write_all() return model_mgr def tr_miss(happeningid): model_mgr = ModelRequestMgr() BackendApi.tr_happening_missed(model_mgr, happeningid, force=True) model_mgr.write_all() return model_mgr while True: happeninglist = Happening.fetchValues(['id','state'], filters, limit=LIMIT, offset=offset) offset += LIMIT for happening in happeninglist: try: if happening.state == Defines.HappeningState.CLEAR: model_mgr = db_util.run_in_transaction(tr_clear, happening.id) else: model_mgr = db_util.run_in_transaction(tr_miss, happening.id) model_mgr.write_end() except CabaretError, err: if err.code == CabaretError.Code.ALREADY_RECEIVED: pass else: raise print 'update %d end' % happening.id if len(happeninglist) < LIMIT: break
def check(self): # 進行情報があるかを確認. playdata = Happening.getByKey(self.__happening.id) if playdata is None or not playdata.is_canceled(): raise AppTestError(u'進行情報が保存されていない')
def handle(self, *args, **options): starttime = OSAUtil.get_now() print '================================' print 'distribute_raidprize' print '================================' print 'start:%s' % starttime.strftime("%Y-%m-%d %H:%M:%S") LIMIT_PER_REQUEST = 100 LOOP_NUM_MAX = 10000 is_daemon = args and args[0] == '1' # wsgi.pyのタイムスタンプを記録. wsgi_py_file = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../../../wsgi.py')) wsgi_py_timestamp = os.stat(wsgi_py_file).st_mtime # wsgi.pyのタイムスタンプを確認. def check_timestamp(): return os.stat(wsgi_py_file).st_mtime == wsgi_py_timestamp # pidの有無. def check_pid(): if not is_daemon: return True elif os.path.exists('/var/run/distribute_raidprize.pid'): return True return False def tr_distribute(queue, happening, raidboss, help_prizelist): model_mgr = ModelRequestMgr() BackendApi.tr_distribute_raid(model_mgr, queue, happening, raidboss, help_prizelist) model_mgr.write_all() return model_mgr model_mgr = ModelRequestMgr() client = Client.get(config.REDIS_LOG) key = 'distribute_raidprize_last_id' prev = str(client.get(key)) prev = int(prev) if prev.isdigit() else 0 loop = 0 while loop < LOOP_NUM_MAX: if not check_timestamp(): print 'server is updated!!' break elif not check_pid(): print 'process killed!!' break loop += 1 # 報酬のキューを取得. queuelist = RaidPrizeDistributeQueue.fetchValues(limit=LIMIT_PER_REQUEST, using=settings.DB_READONLY) if not queuelist: # ちょっと休憩. time.sleep(1) continue queue = queuelist[0] if queue.id == prev: # 遅延の可能性. time.sleep(1) continue delete_only_list = [] for queue in queuelist: if not check_timestamp(): break elif not check_pid(): break # レイドを取得. happeningset = BackendApi.get_happening(model_mgr, queue.raidid, using=settings.DB_READONLY) raidboss = None help_prizelist = None if happeningset: raidboss = BackendApi.get_raid(model_mgr, queue.raidid, using=settings.DB_READONLY, happening_eventvalue=happeningset.happening.event) if not happeningset.happening.is_end(): happening = Happening.getByKey(queue.raidid, using=settings.DB_READONLY) if not happening.is_end(): DbgLogger.write_error(u'distribute not end...queue=%s' % queue.id) continue happeningset = HappeningSet(happening, happeningset.master) if raidboss: raid = Raid.getByKey(queue.raidid, using=settings.DB_READONLY) if raid: raidboss = RaidBoss(raid, raidboss.master, raidboss.raideventraidmaster) if raidboss: help_prizelist = BackendApi.get_prizelist(model_mgr, raidboss.master.helpprizes) if raidboss: # 書き込み. try: db_util.run_in_transaction_custom_retries(0, tr_distribute, queue, happeningset.happening, raidboss, help_prizelist).write_end() except Exception, err: DbgLogger.write_error(u'distribute failure...queue=%s,%s' % (queue.id, err)) if settings_sub.IS_DEV: raise else: DbgLogger.write_error(u'distribute:raid is not found...raidid=%s' % queue.raidid) delete_only_list.append(queue.id) prev = queue.id if delete_only_list: # 削除するだけのものを削除. RaidPrizeDistributeQueue.all().filter(id__in=delete_only_list).delete()
def __procSearch(self): """レイド検索. """ def to_i(v): if str(v).isdigit(): return int(v) else: return None serchtype = self.request.get('_serchtype') value = self.request.get('_value') state = to_i(self.request.get('_state')) or Defines.HappeningState.END page = (to_i(self.request.get('_page')) or 0) model_mgr = self.getModelMgr() raid_all = dict([ (master.id, master) for master in model_mgr.get_mastermodel_all( RaidMaster, fetch_deleted=True, using=settings.DB_READONLY) ]) uid = None if serchtype == 'uid': uid = to_i(value) elif serchtype == 'dmmid': uid = BackendApi.dmmid_to_appuid( self, [value], using=settings.DB_READONLY).get(value) if uid: PAGE_CONTENT_NUM = 100 filters = { 'oid': uid, 'state': state, } nummax = Happening.count(filters, using=settings.DB_READONLY) page_max = (nummax + PAGE_CONTENT_NUM - 1) / PAGE_CONTENT_NUM offset = page * PAGE_CONTENT_NUM recordlist = Happening.fetchValues(filters=filters, order_by='-ctime', limit=PAGE_CONTENT_NUM, offset=offset, using=settings.DB_READONLY) raiddict = BackendApi.get_model_dict( model_mgr, Raid, [record.id for record in recordlist], using=settings.DB_READONLY) raidlist = [] for record in recordlist: raid = raiddict.get(record.id) master = None if raid: master = raid_all.get(record.mid) if master: raidlist.append({ 'id': record.id, 'mid': master.id, 'name': master.name, 'level': record.level, 'ctime': DateTimeUtil.dateTimeToStr(record.ctime), 'url': self.makeAppLinkUrlAdmin(UrlMaker.view_raid(record.id)) }) else: raidlist.append({ 'id': record.id, 'mid': record.mid, 'name': u'不明', 'level': record.level, 'ctime': DateTimeUtil.dateTimeToStr(record.ctime), 'url': None }) url = UrlMaker.view_raid() url = OSAUtil.addQuery(url, '_serchtype', serchtype) url = OSAUtil.addQuery(url, '_value', value) url = OSAUtil.addQuery(url, '_state', state) def __makePage(index): return { 'num': index, 'url': self.makeAppLinkUrlAdmin( OSAUtil.addQuery(url, '_page', index - 1)), } pagination_data = { 'page_list': [__makePage(p) for p in xrange(1, page_max)], 'now_page': __makePage(page + 1), 'has_next': False, 'has_prev': False, } if page < page_max: pagination_data['next_page'] = __makePage(page + 1) pagination_data['has_next'] = True if 1 < page: pagination_data['prev_page'] = __makePage(page - 1) pagination_data['has_prev'] = True self.html_param['pagination'] = pagination_data self.html_param['raidlist'] = raidlist self.html_param['serchtype'] = serchtype self.html_param['state'] = state self.html_param['value'] = value self.writeAppHtml('infomations/view_raid/search')