當前位置: 首頁>>代碼示例>>Python>>正文


Python Timer.getWaitTimeForNextHour方法代碼示例

本文整理匯總了Python中Timer.getWaitTimeForNextHour方法的典型用法代碼示例。如果您正苦於以下問題:Python Timer.getWaitTimeForNextHour方法的具體用法?Python Timer.getWaitTimeForNextHour怎麽用?Python Timer.getWaitTimeForNextHour使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Timer的用法示例。


在下文中一共展示了Timer.getWaitTimeForNextHour方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: start

# 需要導入模塊: import Timer [as 別名]
# 或者: from Timer import getWaitTimeForNextHour [as 別名]
	def start(self):
		from Log import *
		Log.debug("Start scheduler")

		timer = Timer()
		timer.setCurrentDateAndTime()

		processID = os.getpid()
		Log.debug("Start to operate bot [" + str(processID) + "]\n")
		
		# Make a pattern		
		self.patternDelegator.startToGetPattern(self.jobHashMap)

		Log.debug("=============================================")
		Log.debug("=================== Ready ===================")
		Log.debug("=============================================")

		while self.continued:
			try:				
				start = self.checkNextHour(timer)
								
				# After generating the pattern
				# Send the report to the manager
				# and wait for the start message				
				if self.firstStep:
					#Log.debug("Send the action message to the manager\n")
					#reportToSend = makeManagerJsonData(self.userID)
					#recvMsgFromManager = self.networkingWithManager(reportToSend)
					self.firstStep = False
				
					#if len(recvMsgFromManager) == 0:
					#	Log.error("Fail to receive the action message from the manager")
					#	self.continued = False
					#	continue							

				if start:
					Log.debug("=============================================")
					Log.debug("=================== Start ===================")
					Log.debug("=============================================")

				currentHour = timer.getCurrentHour()

				while start:					
					nextJobToWork = self.jobHashMap.dequeJobValueByKey(currentHour)

					if nextJobToWork == 0:						
						start = False
						Log.debug("Complete sending requests")
						break
							
					delay = random.randrange(1, 6)
					time.sleep(delay)

					Log.debug("Start to communicate with servers\n")
					dstName = self.getDstName(nextJobToWork)

					Log.debug("Start to find dstName in Hash\n")
					if not self.isIncludedInHash(dstName):
						dstIPAddress = self.startToCommunicationWithBroker(nextJobToWork)
						self.addInHash(dstName, dstIPAddress)

					if self.hash_dstIPAddress[dstName]:
						self.startToCommunicateWithService(nextJobToWork, dstIPAddress)

				if not self.continued:
					break
				
				Log.debug("Wait for next hour\n")
				wait = timer.getWaitTimeForNextHour()
				time.sleep(wait)
				timer.setCurrentDateAndTime()
			except Exception as e:
				Log.error("There is error in scheduler")
				Log.error(e)
				sys.exit(1)

		Log.debug("Successfully end the one day job")
		sys.exit(0)
開發者ID:timewizhan,項目名稱:MSProject,代碼行數:80,代碼來源:Scheduler.py


注:本文中的Timer.getWaitTimeForNextHour方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。