+ self.ensure_timer_from_until(lease['t_from'],lease['t_until'])
+
+ # assuming t1<t2
+ def ensure_timer_from_until (self, t1,t2):
+ now=int(time.time())
+ # both times are in the past: forget about it
+ if t2 < now : return
+ # we're in the middle of the lease: make sure to arm a callback in the near future for checking
+ # this mostly is for starting the slice if nodemanager gets started in the middle of a lease
+ if t1 < now :
+ self.ensure_timer (now,now+10)
+ # both are in the future : arm them
+ else :
+ self.ensure_timer (now,self.round_time(t1))
+ self.ensure_timer (now,self.round_time(t2))
+
+ def ensure_timer(self, now, timestamp):
+ if timestamp in self.timers: return
+ def this_closure ():
+ import time
+ logger.log("TIMER trigering at %s (was armed at %s, expected to trigger at %s)"%\
+ (reservation.time_printable(time.time()),
+ reservation.time_printable(now),
+ reservation.time_printable(timestamp)))
+ self.granularity_callback (now)
+ timer=threading.Timer(timestamp-now,this_closure)
+ self.timers[timestamp]=timer
+ timer.start()