Beispiel #1
0
	def delete(self,ctx=None):
		with log_wait("wait","delete2",self.name):
			with self._lock:
				if self._plinger:
					self.stop_job('_plinger')
					assert self._plinger is None
					#log(TRACE,"WaitDel",self.name)
					super(Waiter,self).delete(ctx=ctx)
					self.job.set(False)
Beispiel #2
0
	def one_value(self, step):
		"""\
			Get one value from some "set monitor" command.
			Override this for active monitoring.
			"""
		if self.send_check_event and step==1:
			process_event(Event(self.ctx, "monitor","checking",*self.name))

		with log_wait("monitor","one_value",*self.name):
			return self.watcher.get(block=True, timeout=None)
Beispiel #3
0
	def up(self):
		with log_wait("monitor up "+repr(self)):
			while self.job and self.job.dead:
				gevent.sleep(0.1) # link will clear

		if not self.job:
			self.value = None
			process_event(Event(Context(),"monitor","start",*self.name))
			self.start_job("job",self._run_loop)
			self.state_change_at = now()

			def tell_ended(_):
				simple_event(Context(),"monitor","stop",*self.name)
			self.job.link(tell_ended)
Beispiel #4
0
	def sleep(force,timeout,debugi=""):
		global current_slot,real_sleep
		from homevent.twist import log_wait,callLater
		if force:
			real_sleep += 1
		try:
			with log_wait("%s %s: %s timer wait for %s" % (now(False),debugi,"Forced" if force else "Fake", timeout)):
				t = now(force)
				while unixdelta(now(force) - t) < timeout:
					gevent.sleep(1/SLOT/real_sleep if real_sleep else 0.001)
					current_slot += 1/real_sleep+0.00001 if real_sleep else 1

			global _log,TRACE
			if _log is None:
				from homevent.logging import log as _log, TRACE
			_log(TRACE,"%s %s: %s timer done" % (now(False),debugi,"Forced" if force else "Fake"))
			
		finally:
			if force:
				real_sleep += -1
Beispiel #5
0
	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)
Beispiel #6
0
	def retime(self, dest):
		simple_event("wait","update",*self.name,dest=dest, loglevel=TRACE)
		with log_wait("wait","delete1",self.name):
			with self._lock:
				self.end = dest
				self._set_pling()