Пример #1
0
    def run(self):
        if self._initdelay:
            self._standby(self._initdelay)
        self._runtime = time.time()
        while self._running:
            start = time.time()
            if not (xdm.xdm_states[0] in xdm.common.STATES or\
                    xdm.xdm_states[1] in xdm.common.STATES or\
                    xdm.xdm_states[3] in xdm.common.STATES or\
                    xdm.xdm_states[6] in xdm.common.STATES):
                self._sleeping = 0
                self._blockCount = 0
                self._neverRun = False
                self._runNow = False
                self._lastRun = datetime.datetime.now()
                try:
                    self._action()
                    # this is here to test the failMessage gui
                    """if 'coreUpdateCheck' == self.name and not self._fails:
                        raise AttributeError("fake error on first run")"""
                except:
                    self._fails += 1
                    self._failMessage = log.error('Error in the scheduler thread of %s. %s fails so far.' % (self.name, self._fails))
                    if self._fails >= MAXIMUM_FAILS:
                        log.error('This scheduler %s is dead to me!' % self.name)
                        self._running = 0
                        break
            else:
                self._blockCount += 1
                log("XDM is in state %s not running action: %s" % (xdm.common.STATES, self.name))

            self._runtime += self._loopdelay
            self._sleeping = 1

            if self._neverRun and self._initdelay:
                # this will create times like -10 and -20 later this will be -(-20) = 20
                timeDelta = min(5 * 60, (self._blockCount * self._initdelay))
                sleepTime = max(0, self._initdelay + timeDelta)
            else:
                # this will reduce the _loopdelay by half for each time we have been blocked
                # e.g. looptime = 120s _blockCount = 1
                # = minus 60s
                # e.g. looptime = 120s _blockCount = 2
                # = minus 90s
                # the key is the 0.5 ** _blockCount ... ** means "to the power of"
                timeDelta = self._loopdelay - ((0.5 ** self._blockCount) * self._loopdelay)
                sleepTime = max(0, (self._runtime - start) - timeDelta)
            if self._blockCount:
                # these lines are from hell
                if self._neverRun:
                    log("Adding %s seconds because %s has been blocked, before it's first run, %s times. I will sleep for %ss instead of %ss thats %s%% if the normal time" % \
                        (timeDelta, self.name, self._blockCount, sleepTime, self._initdelay, int((sleepTime / self._initdelay) * 100)))
                else:
                    log("Removing %s seconds because %s has been blocked %s times. I will sleep for %ss instead of %ss thats %s%% if the normal time" % \
                        (timeDelta, self.name, self._blockCount, sleepTime, self._loopdelay, 100 - int((sleepTime / self._loopdelay) * 100)))

            self._nextRun = self._calcNextRun(sleepTime)
            self._standby(sleepTime)
Пример #2
0
 def run(self):
     if self._initdelay:
         time.sleep(self._initdelay)
     self._runtime = time.time()
     while self._running:
         start = time.time()
         try:
             self._action()
         except:
             self._fails += 1
             log.error('Error in the scheduler thread of %s. %s fails so far.' % (self._action.__name__, self._fails))
             if self._fails >= MAXIMUM_FAILS:
                 log.error('This scheduler %s is dead to me!' % self._action.__name__)
                 self._running = 0
                 break
         self._runtime += self._loopdelay
         time.sleep(max(0, self._runtime - start))
Пример #3
0
 def run(self):
     if self._initdelay:
         time.sleep(self._initdelay)
     self._runtime = time.time()
     while self._running:
         start = time.time()
         try:
             self._action()
         except:
             self._fails += 1
             log.error(
                 'Error in the scheduler thread of %s. %s fails so far.' %
                 (self._action.__name__, self._fails))
             if self._fails >= MAXIMUM_FAILS:
                 log.error('This scheduler %s is dead to me!' %
                           self._action.__name__)
                 self._running = 0
                 break
         self._runtime += self._loopdelay
         time.sleep(max(0, self._runtime - start))
Пример #4
0
    def run(self):
        if self._initdelay:
            self._standby(self._initdelay)
        self._runtime = time.time()
        while self._running:
            start = time.time()
            if not (xdm.xdm_states[0] in xdm.common.STATES or\
                    xdm.xdm_states[1] in xdm.common.STATES or\
                    xdm.xdm_states[3] in xdm.common.STATES or\
                    xdm.xdm_states[6] in xdm.common.STATES):
                self._sleeping = 0
                self._blockCount = 0
                self._neverRun = False
                self._runNow = False
                self._lastRun = datetime.datetime.now()
                try:
                    self._action()
                    # this is here to test the failMessage gui
                    """if 'coreUpdateCheck' == self.name and not self._fails:
                        raise AttributeError("fake error on first run")"""
                except:
                    self._fails += 1
                    self._failMessage = log.error(
                        'Error in the scheduler thread of %s. %s fails so far.'
                        % (self.name, self._fails))
                    if self._fails >= MAXIMUM_FAILS:
                        log.error('This scheduler %s is dead to me!' %
                                  self.name)
                        self._running = 0
                        break
            else:
                self._blockCount += 1
                log("XDM is in state %s not running action: %s" %
                    (xdm.common.STATES, self.name))

            self._runtime += self._loopdelay
            self._sleeping = 1

            if self._neverRun and self._initdelay:
                # this will create times like -10 and -20 later this will be -(-20) = 20
                timeDelta = min(5 * 60, (self._blockCount * self._initdelay))
                sleepTime = max(0, self._initdelay + timeDelta)
            else:
                # this will reduce the _loopdelay by half for each time we have been blocked
                # e.g. looptime = 120s _blockCount = 1
                # = minus 60s
                # e.g. looptime = 120s _blockCount = 2
                # = minus 90s
                # the key is the 0.5 ** _blockCount ... ** means "to the power of"
                timeDelta = self._loopdelay - (
                    (0.5**self._blockCount) * self._loopdelay)
                sleepTime = max(0, (self._runtime - start) - timeDelta)
            if self._blockCount:
                # these lines are from hell
                if self._neverRun:
                    log("Adding %s seconds because %s has been blocked, before it's first run, %s times. I will sleep for %ss instead of %ss thats %s%% if the normal time" % \
                        (timeDelta, self.name, self._blockCount, sleepTime, self._initdelay, int((sleepTime / self._initdelay) * 100)))
                else:
                    log("Removing %s seconds because %s has been blocked %s times. I will sleep for %ss instead of %ss thats %s%% if the normal time" % \
                        (timeDelta, self.name, self._blockCount, sleepTime, self._loopdelay, 100 - int((sleepTime / self._loopdelay) * 100)))

            self._nextRun = self._calcNextRun(sleepTime)
            self._standby(sleepTime)