def run(self):
    self.helper.log_info('starting valhalla connector...')
    while True:
        try:
            status_data = self.valhalla_client.get_status()
            api_status = Status.parse_obj(status_data)
            self.helper.log_info(f'current valhalla status: {api_status}')
            current_time = int(datetime.utcnow().timestamp())
            current_state = self._load_state()
            self.helper.log_info(f'loaded state: {current_state}')
            last_run = self._get_state_value(current_state, self._STATE_LAST_RUN)
            last_valhalla_version = self._get_state_value(current_state, self._VALHALLA_LAST_VERSION)
            if (self._is_scheduled(last_run, current_time) and self._check_version(last_valhalla_version, api_status.version)):
                self.helper.log_info('running importers')
                knowledge_importer_state = self._run_knowledge_importer(current_state)
                self.helper.log_info('done with running importers')
                new_state = current_state.copy()
                new_state.update(knowledge_importer_state)
                new_state[self._STATE_LAST_RUN] = int(datetime.utcnow().timestamp())
                new_state[self._VALHALLA_LAST_VERSION] = api_status.version
                self.helper.log_info(f'storing new state: {new_state}')
                self.helper.set_state(new_state)
                self.helper.log_info(f'state stored, next run in: {self._get_interval()} seconds')
            else:
                new_interval = (self._get_interval() - (current_time - last_run))
                self.helper.log_info(f'connector will not run, next run in: {new_interval} seconds')
            time.sleep(60)
        except (KeyboardInterrupt, SystemExit):
            self.helper.log_info('connector stop')
            exit(0)
        except Exception as e:
            self.helper.log_error(str(e))
            exit(0)
def run(self):
    self.helper.log_info('starting valhalla connector...')
    while True:
        try:
            status_data = self.valhalla_client.get_status()
            api_status = Status.parse_obj(status_data)
            self.helper.log_info(f'current valhalla status: {api_status}')
            current_time = int(datetime.utcnow().timestamp())
            current_state = self._load_state()
            self.helper.log_info(f'loaded state: {current_state}')
            last_run = self._get_state_value(current_state, self._STATE_LAST_RUN)
            last_valhalla_version = self._get_state_value(current_state, self._VALHALLA_LAST_VERSION)
            if (self._is_scheduled(last_run, current_time) and self._check_version(last_valhalla_version, api_status.version)):
                self.helper.log_info('running importers')
                knowledge_importer_state = self._run_knowledge_importer(current_state)
                self.helper.log_info('done with running importers')
                new_state = current_state.copy()
                new_state.update(knowledge_importer_state)
                new_state[self._STATE_LAST_RUN] = int(datetime.utcnow().timestamp())
                new_state[self._VALHALLA_LAST_VERSION] = api_status.version
                self.helper.log_info(f'storing new state: {new_state}')
                self.helper.set_state(new_state)
                self.helper.log_info(f'state stored, next run in: {self._get_interval()} seconds')
            else:
                new_interval = (self._get_interval() - (current_time - last_run))
                self.helper.log_info(f'connector will not run, next run in: {new_interval} seconds')
            time.sleep(60)
        except (KeyboardInterrupt, SystemExit):
            self.helper.log_info('connector stop')
            exit(0)
        except Exception as e:
            self.helper.log_error(str(e))
            exit(0)