def pause(self): debug ("timer service paused") self.paused = True
def tick(self): info ("TICK") # calculate the passed time diff = datetime.datetime.now() - self.last_tick # count down the extension if any if self.extension: new_ext = self.extension - diff if new_ext.date() != self.extension.date(): self.extension = None info ("Extension exhausted!") else: self.extension = new_ext debug ("Extension: %s" % self.extension.time()) else: info ("No extension") # if we're paused, we don't send any alerts and don't count the usage if self.paused: return # increment the usage time # if the new usage is at a new date -> set the usage to 0 new_usage = self.usage + diff if new_usage.date() != self.usage.date(): debug ("usage has crossed the date border -> setting it to 0") self.usage = datetime.datetime.today().replace(hour=0, minute=0, second=0, microsecond=0) else: self.usage = new_usage info ("Usage: %s" % new_usage.time()) # remember the last time of increment self.last_tick = datetime.datetime.now() # if we're not supposed to send alerts, we're done here if not self.send_alerts: debug ("Alerts are deactivated") return # if we're running on an extension, we're done here if self.extension: debug ("We're in an extension, don't send any alerts") return alert = False # if the usage exceeds the daily contingent -> timer_alert if self.usage.time() > self.config_service.dailyContingent: info ("Usage exceeds the daily contingent!") alert = True # if there's no contingent related alert -> check lock times if not alert: for tme in self.config_service.lock_times: if tme.is_in(datetime.datetime.now().time()): info ("We are in a locked timeslice!") alert = True break # execute timer alert if necessary if alert: self.deactivate_alerts() start_new_thread(self.callback.timer_alert, ()) info ("END OF TICK")
def deactivate_alerts(self): debug ("deactivating alerts") self.send_alerts = False
def activate_alerts(self): debug ("activating alerts") self.send_alerts = True
def resume(self): debug ("timer service resumed") self.paused = False