def main(): """Perform db cleanup for old resources. Remove load balancers from database, which have been deleted have since expired. """ # perform the rituals service.prepare_service(sys.argv) gmr.TextGuruMeditation.setup_autorun(version) signal.signal(signal.SIGHUP, _mutate_config) # Read configuration interval = CONF.house_keeping.cleanup_interval lb_expiry = CONF.house_keeping.load_balancer_expiry_age # initialize prometheus.start_http_server(PROMETHEUS_PORT) db_cleanup = house_keeping.DatabaseCleanup() LOG.info("Starting house keeping at %s", str(datetime.datetime.utcnow())) # start cleanup cycle while True: LOG.debug("Housekeeping") _metric_housekeeping.inc() try: db_cleanup.cleanup_load_balancers() except Exception as e: LOG.error( 'Housekeeping caught the following exception: {}'.format(e)) _metric_housekeeping_exceptions.inc() time.sleep(interval)
def setUp(self): super(TestDatabaseCleanup, self).setUp() self.dbclean = house_keeping.DatabaseCleanup() self.amp_health_repo = mock.MagicMock() self.amp_repo = mock.MagicMock() self.amp = repo.AmphoraRepository() self.dbclean.amp_repo = self.amp_repo self.dbclean.amp_health_repo = self.amp_health_repo self.CONF = cfg.CONF
def setUp(self): super().setUp() self.dbclean = house_keeping.DatabaseCleanup() self.amp_health_repo = mock.MagicMock() self.amp_repo = mock.MagicMock() self.amp = repo.AmphoraRepository() self.lb = repo.LoadBalancerRepository() self.dbclean.amp_repo = self.amp_repo self.dbclean.amp_health_repo = self.amp_health_repo self.CONF = self.useFixture(oslo_fixture.Config(cfg.CONF))
def db_cleanup(): """Perform db cleanup for old amphora.""" # Read the interval from CONF interval = CONF.house_keeping.cleanup_interval LOG.info(_LI("DB cleanup interval is set to %d sec"), interval) LOG.info(_LI('Amphora expiry age is %s seconds'), CONF.house_keeping.amphora_expiry_age) db_cleanup = house_keeping.DatabaseCleanup() while db_cleanup_thread_event.is_set(): LOG.debug("Initiating the cleanup of old amphora...") db_cleanup.delete_old_amphorae() time.sleep(interval)
def db_cleanup(): """Perform db cleanup for old resources.""" # Read the interval from CONF interval = CONF.house_keeping.cleanup_interval LOG.info("DB cleanup interval is set to %d sec", interval) LOG.info('Amphora expiry age is %s seconds', CONF.house_keeping.amphora_expiry_age) LOG.info('Load balancer expiry age is %s seconds', CONF.house_keeping.load_balancer_expiry_age) db_cleanup = house_keeping.DatabaseCleanup() while not db_cleanup_thread_event.is_set(): LOG.debug("Initiating the cleanup of old resources...") db_cleanup.delete_old_amphorae() db_cleanup.cleanup_load_balancers() db_cleanup_thread_event.wait(interval)