def maybe_up(self, resync = False): if self.running not in ("off","error"): return if self.last is not None: self.running = "next" self.next = time_delta(self.interval, now=self.last) self.waiter = callLater(False, self.next, self.do_pre)
def up(self, resync=False): if self.running not in ("off","error"): if not resync: raise AlreadyRunningError(self) if resync: self.do_sync() else: self.running = "next" self.next = time_delta(self.interval, now=self.last) self.waiter = callLater(False, self.next, self.do_pre)
def do_post(self): self.slotter = None if self.running != "during" or self.waiter is not None: log(ERROR,"timeslot error post",self.running,*self.name) return self.running = "next" simple_event("timeslot","end",*self.name, deprecated=True) simple_event("timeslot","state",*self.name, state="end") self.next = time_delta(self.interval, now=self.next)-dt.timedelta(0,self.duration) self.waiter = callLater(False, self.next, self.do_pre)
def _schedule(self): """Sleep until the next time this monitor should run""" s = self.stopped_at or now() if self.delay_for: if isinstance(self.delay_for,tuple): s = time_delta(self.delay_for, now=s) else: s += dt.timedelta(0,self.delay_for) if self.delay_until: if self.stopped_at: s = time_until(self.delay_until, now=s, invert=True) s = time_until(self.delay_until, now=s) if not self.delay_for and not self.delay_until: if isinstance(self.delay,tuple): s = time_delta(self.delay, now=s) else: s += dt.timedelta(0,self.delay) self.started_at = s with log_wait("monitor","sleep",*self.name): sleepUntil(False,s)
def delay(): if isinstance(self.delay,tuple): sleepUntil(False,time_delta(self.delay)) else: sleepUntil(False,self.delay)
def delta(): return time_delta(event, now=now(self.parent.force))