def _argusWait(self,secondsToWait): startTime = datetime.now() #self._log("Observing recorder queue for %s. Use 'sleepModeOn' for VCR mode"%OSTools.convertSecondsToString(secondsToWait)) self._log("Observing recorder queue until %s. Execute 'sleepModeOn' for VCR mode"%OSTools.showDateTimeWithOffset(secondsToWait)) lastQCheck=None while (OSTools.getDifferenceInSeconds(datetime.now(),startTime) < secondsToWait): xtime.sleep(self.PRERUN_SECONDS) path=self._config().getRecQueuePath() try: currentModificationTime=OSTools.getLastModificationTime(path) except OSError as osError: currentModificationTime=0.0 self._config().logError("Error checking rec file:"+osError.strerror) print("Error checking rec file") #check for socket or file changes... if lastQCheck is None: lastQCheck=currentModificationTime #we came from a queue check-so thats the last time we checked if currentModificationTime-lastQCheck>0: self._log("Rec Q modified-looking for jobs") return False if self._daemon.isVCRPolicyChangeRequested(): return False return True
def _secondsUntilNextRun(self,startTime,prerunSeconds): now = datetime.now() secondsUntilStart = OSTools.getDifferenceInSeconds(startTime, now) secondsToSleep = secondsUntilStart - prerunSeconds #wake up a minute+ before if secondsToSleep < prerunSeconds: self._log("Next run in less than %s seconds"%(str(secondsUntilStart))) #sleep until time is ready.... no hibernate if secondsUntilStart > 0: self._log("Waiting to launch...."+str(secondsUntilStart)) xtime.sleep(secondsUntilStart) return 0 return secondsToSleep
def _monitorCurrentRecording(self,recProcess,recordingJob): done = False #this is testing: emergencyCount=0; jobID=recordingJob.getEPGInfo().getJobID() isRecurrentWriteError=False recPath = self._config.getRecordingPath() videoSize=OSTools.getDirectorySize(recPath) xtime.sleep(self.HEARTBEAT) self._log("Monitoring JOB "+jobID) while not done: result = recProcess.poll() isAlive = result is None if isAlive: currentSize = OSTools.getDirectorySize(recPath) delta = currentSize - videoSize print(("JOB "+jobID+" - bytes written:"+str(delta))) #live sign- not logging videoSize = currentSize if delta == 0: self._log("JOB "+jobID+" does not write any data") if isRecurrentWriteError: done=True self._log("Terminating Rec process, preventing reschedule.. ") recProcess.terminate() self.__handleProcessTermination(recProcess) isRecurrentWriteError=True #only on retry permitted else: self._log("Quit JOB "+jobID) self.__handleProcessTermination(recProcess) done=True if not done: #Ensure that an adjacent job can follow - decrease the wait time gludu=recordingJob.getGluedDurance() endtime = OSTools.addToDateTime(recordingJob.getExecutionTime(),gludu) delta = max(10,OSTools.getDifferenceInSeconds(endtime,datetime.now())) sleepTime = min(self.HEARTBEAT,delta) if sleepTime != self.HEARTBEAT: emergencyCount+=1; endTimeString=endtime.strftime("%H:%M.%S") startTimeString = recordingJob.getExecutionTime().strftime("%H:%M.%S") self._log("Stopping in seconds: %d (Info Start: %s expected end: %s with dur %d)"%(sleepTime,startTimeString,endTimeString,gludu))#log only the fragments if emergencyCount > 10: self._log("REC Q error- force process termination") recProcess.terminate() self.__handleProcessTermination(recProcess) done=True xtime.sleep(sleepTime) self._log("JOB "+jobID+" is done") OSTools.syncFiles()
def _wasWakeupScheduled(self,startTime): now = datetime.now() secondsToWait = OSTools.getDifferenceInSeconds(startTime, now) duranceStr = OSTools.convertSecondsToString(secondsToWait) self._log("Delta durance to scheduled wakeup:"+duranceStr) if secondsToWait > self.PRERUN_SECONDS: self._log("Suspend interrupted by user-> going into Server mode!") return False if secondsToWait>0: self._log("Waiting until record starts:"+duranceStr) xtime.sleep(secondsToWait) return True
def _isTimeLeftForEPGUpdate(self,nextStartTime): now = datetime.now() seconds = OSTools.getDifferenceInSeconds(nextStartTime, now) return seconds > self.HEARTBEAT*10