def ExecNextCheck(self): bRetValue = False # 如果还没有开始连接,那么,开始连接 if (not self.s_iExecConnectSockIndex): self.s_iExecConnectSockIndex = self.s_execHLSockMang.CreateConnectSock( self.s_strDestSrvName, self.s_iDestPort) self.s_lastSendTime = datetime(2017, 1, 1) self.s_bWaitReply = False bRetValue = True # 是否已经连接成功 if (self.s_execHLSockMang.IsSockConnectSuccess( self.s_iExecConnectSockIndex)): # 如果数据发送后,长时间数据未到达,可能对方重启了,本地重启连接 if (self.s_bWaitReply): if (CTYLB_MainSys_MiscFunc.CheckIdleTime( self.s_lastSendTime, self.s_iCheckReconnectTime)): self.s_execHLSockMang.CloseSockByIndex( self.s_iExecConnectSockIndex) self.s_iExecConnectSockIndex = 0 pass if (self.s_iExecConnectSockIndex): bSockExist, recvCTArray = self.s_execHLSockMang.PassiveRecv_From_ConnectSock( self.s_iExecConnectSockIndex) if (not bSockExist): self.s_iExecConnectSockIndex = 0 else: if (recvCTArray): self.s_lastRecvCTArray.extend(recvCTArray) self.s_bWaitReply = False bRetValue = True return bRetValue
def IsHostTimeOut(self): bTimeOut = False if (self.s_lastClientStatusData): if (CTYLB_MainSys_MiscFunc.CheckIdleTime( self.s_lastRecvStatusTime, CTYLB_TaskCenter_HostMang.s_g_iMaxClientOffLineIdleTime)): bTimeOut = True return bTimeOut
def CanExecSendData(self): bRetValue = False if (not self.s_lastRecvCTArray): if (self.s_execHLSockMang.IsSockConnectSuccess( self.s_iExecConnectSockIndex)): if (not self.s_bWaitReply): if (CTYLB_MainSys_MiscFunc.CheckIdleTime( self.s_lastSendTime, self.s_iNextSendWaitCheckTick)): bRetValue = True return bRetValue
def TimerCheck_UserMoodCheckTime(self, dbConn): bRetValue = False # 每2秒钟检查一次 if (CTYLB_MainSys_MiscFunc.CheckIdleTime( self.s_lastCheckUserMoodTime, CTYReActBrainBot_Track_Checker.s_g_iTaskCheckDiffTime)): self.s_lastCheckUserMoodTime = datetime.now() # 获得用户单独对话的列表 iUserFaceToFaceEnvRecArray = CSkLBDB_ea_brain_envirument.GetRecList_By_GroupName( dbConn, '') if (iUserFaceToFaceEnvRecArray): bRetValue = True for iEachUserEnvRecID in iUserFaceToFaceEnvRecArray: curCheckUserExec = CUserExecReal(dbConn, iEachUserEnvRecID) iContentType, strActiveSendContent = curCheckUserExec.CheckActive_DaShan_SayContent( ) if (strActiveSendContent): CTYReActBrainBot_Track_Checker.AddReplyTextInfoToUser( dbConn, iEachUserEnvRecID, strActiveSendContent) pass return bRetValue
def TimerCheck_ScheduleAlwaysTask(self, dbConn): bRetValue = False # 任务表,已经完成了的,但是,又需要总是运行的 recIDArray = CSkLBDB_ea_brain_exec_task.GetRecList_By_Status_AlwaysValue( dbConn, CTYOp_ReActBrain_Store.s_g_iStatus_Finish, 1) if (recIDArray): bRetValue = True for iEachRecID in recIDArray: CSkLBDB_ea_brain_exec_task.Update_ExStatus( dbConn, iEachRecID, CTYOp_ReActBrain_Store.s_g_iStatus_Free) # 每2秒钟检查一次 if (CTYLB_MainSys_MiscFunc.CheckIdleTime( self.s_iLastCheckTaskTime, CTYReActBrainBot_Track_Checker.s_g_iTaskCheckDiffTime)): self.s_iLastCheckTaskTime = datetime.now() # 检查当前用户环境可否需要输出 # 检查任务表中,已经提交,但长时间未启动的,提示,当前系统忙还需要等待。 waitLongTimeRecArray = CSkLBDB_ea_brain_exec_task.GetRecList_By_Status( dbConn, CTYOp_ReActBrain_Store.s_g_iStatus_Free) for iEachWaitRecID in waitLongTimeRecArray: iUserEnvID, lastCheckTime = CSkLBDB_ea_brain_exec_task.Read_EnvID_LastCheckTIme_By_RecID( dbConn, iEachWaitRecID) if (CTYLB_MainSys_MiscFunc.CheckIdleTime( lastCheckTime, CTYReActBrainBot_Track_Checker. s_g_iTask_WaitStart_MaxIdleTime)): lastCheckTime = datetime.now() curCheckUserExec = CUserExecReal(dbConn, iUserEnvID) if (curCheckUserExec.GetCanTrackTaskLog()): CTYReActBrainBot_Track_Checker.AddReplyTextInfoToUser( dbConn, iUserEnvID, u'系统忙,请稍等,任务还在准备调度') CSkLBDB_ea_brain_exec_task.Update_LastCheckTime( dbConn, iEachWaitRecID, lastCheckTime) # 任务表中,已经启动,但长时间未完成的,提示,当前还在运行 runningLongTimeRecArray = CSkLBDB_ea_brain_exec_task.GetRecList_By_Status( dbConn, CTYOp_ReActBrain_Store.s_g_iStatus_Running) for iEachRunningRecID in waitLongTimeRecArray: iUserEnvID, lastCheckTime = CSkLBDB_ea_brain_exec_task.Read_EnvID_LastCheckTIme_By_RecID( dbConn, iEachRunningRecID) if (CTYLB_MainSys_MiscFunc.CheckIdleTime( lastCheckTime, CTYReActBrainBot_Track_Checker. s_g_iTask_Running_MaxWaitTime)): lastCheckTime = datetime.now() curCheckUserExec = CUserExecReal(dbConn, iUserEnvID) if (curCheckUserExec.GetCanTrackTaskLog()): lastRequestExecTime = CSkLBDB_ea_brain_exec_task.Read_RequestExecTime_By_RecID( dbConn, iUserEnvID) if (lastRequestExecTime): timeDiff = datetime.now() - lastRequestExecTime strWaitTime = u'%d秒' % (timeDiff.seconds) else: strWaitTime = u'%d秒以上' % ( CTYReActBrainBot_Track_Checker. s_g_iTask_Running_MaxWaitTime) CTYReActBrainBot_Track_Checker.AddReplyTextInfoToUser( dbConn, iUserEnvID, u'任务正在运行,请等待,开始时间已经有 %s 了' % (strWaitTime)) CSkLBDB_ea_brain_exec_task.Update_LastCheckTime( dbConn, iEachRunningRecID, lastCheckTime) pass return bRetValue