def _is_exact_match(cron, ts): """Handle edge in case when both parameters are equal. Handle edge case where if the timestamp is the same as the cron point in time to the minute, croniter returns the previous start, not the current. We can check this by first going one step back and then one step forward and check if we are at the original point in time. """ cron.get_prev() diff = timeutils.total_seconds(ts - cron.get_next(datetime.datetime)) return abs(diff) < 60 # minute precision
def wait_down_agents(self, agent_type, agent_dead_limit): """Gives chance for agents to send a heartbeat.""" # check for an abrupt clock change since last check. if a change is # detected, sleep for a while to let the agents check in. tdelta = timeutils.utcnow() - getattr(self, '_clock_jump_canary', timeutils.utcnow()) if timeutils.total_seconds(tdelta) > cfg.CONF.agent_down_time: LOG.warn(_LW("Time since last %s agent reschedule check has " "exceeded the interval between checks. Waiting " "before check to allow agents to send a heartbeat " "in case there was a clock adjustment."), agent_type) time.sleep(agent_dead_limit) self._clock_jump_canary = timeutils.utcnow()
def test_total_seconds(self): delta = datetime.timedelta(days=1, hours=2, minutes=3, seconds=4.5) self.assertAlmostEquals(93784.5, timeutils.total_seconds(delta))
def service_is_up(service): """Check whether a service is up based on last heartbeat.""" last_heartbeat = service['updated_at'] or service['created_at'] # Timestamps in DB are UTC. elapsed = timeutils.total_seconds(timeutils.utcnow() - last_heartbeat) return abs(elapsed) <= CONF.service_down_time