def info(self): if self.running not in ("off","error"): tm = unixdelta(self.next-now()) elif self.last is not None: tm = unixdelta(now()-self.last) else: tm = "never" return "%s %s" % (self.running,tm)
def weigth(self, mod=False): if self.value_tm is None: return None n = now() t = n-self.value_tm nt = self.total_tm+t nts = unixdelta(nt) if mod: self.total_tm = nt if nts == 0: ## called right after init'ing return 0 else: return unixdelta(t) / nts
def weigth(self, mod=False): if self.value_tm is None: return None t = now()-self.value_tm nt = unixdelta(t) if nt == 0: ## called right after init'ing return 0 else: return 1-(1-self.p)**(nt/self.p_base)
def sleepUntil(force,delta): from homevent.times import unixdelta,now,sleep if isinstance(delta,dt.datetime): delta = delta - now() if isinstance(delta,dt.timedelta): delta = unixdelta(delta) if delta < 0: # we're late delta = 0 # but let's hope not too late sleep(force,delta)
def list(self): yield ("name"," ".join(unicode(x) for x in self.name)) yield ("run",self.running) if self.interval is not None: yield ("interval"," ".join(str(x) for x in self.interval)) yield ("duration",self.duration) if self.last is not None: yield ("last",self.last) if self.next is not None: yield ("next",self.next) if self.slotter is not None: yield ("slot",(unixdelta(self.next-now()))/self.duration)
def time_name(self): if self.started_at is None: return "never" if not self.running.is_set(): delta = now() - self.started_at elif self.job: delta = self.started_at - now() else: delta = now() - self.started_at delta = unixdelta(delta) res = humandelta(delta) return u"‹"+res+"›"
def sleepUntil(force,delta): from homevent.times import unixdelta,now if isinstance(delta,dt.datetime): delta = delta - now() if isinstance(delta,dt.timedelta): delta = unixdelta(delta) if delta < 0: # we're late delta = 0 # but let's hope not too late if "HOMEVENT_TEST" in os.environ: ev = AsyncResult() callLater(force,delta, ev.set,None) ev.get(block=True) else: gevent.sleep(delta)
def callLater(force,delta,p,*a,**k): from homevent.times import unixdelta,now if isinstance(delta,dt.datetime): delta = delta - now(force) if isinstance(delta,dt.timedelta): delta = unixdelta(delta) if delta < 0: # we're late delta = 0 # but let's hope not too late if "HOMEVENT_TEST" in os.environ: if force: cl = DelayedCall delta += reactor.realSeconds() else: from homevent.testreactor import FakeDelayedCall cl = FakeDelayedCall delta += reactor.seconds() else: cl = DelayedCall delta += reactor.seconds() cl = cl(reactor,delta, gevent.spawn,(p,)+a,k,seconds=reactor.seconds) return reactor.callLater(cl)
def info(self): if self.total_tm is None: return "(new)" return "%s %s" % (self._calc(), unixdelta(self.total_tm))