From 94e5c4423f12290838b3ea58ad8727255f5d5fae Mon Sep 17 00:00:00 2001 From: Xin Li <137219293+xinlili-statsig@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:58:08 -0700 Subject: [PATCH] more try catch on initialization path (#338) Add more try catch logic --- statsig/spec_store.py | 34 ++++++++++++++++++++-------------- statsig/spec_updater.py | 32 +++++++++++++++++++------------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/statsig/spec_store.py b/statsig/spec_store.py index a7680ab..3388fef 100644 --- a/statsig/spec_store.py +++ b/statsig/spec_store.py @@ -343,18 +343,24 @@ def _get_current_context(self): ) def _get_initialize_strategy(self) -> List[DataSource]: - if self._options.initialize_sources is not None: - return self._options.initialize_sources - strategies = [DataSource.NETWORK] - data_store = self._options.data_store - if data_store is not None: - strategies.insert(0, DataSource.DATASTORE) - if self._options.bootstrap_values: + try: + if self._options.initialize_sources is not None: + return self._options.initialize_sources + strategies = [DataSource.NETWORK] + data_store = self._options.data_store if data_store is not None: - globals.logger.debug("data_store gets priority over bootstrap_values. bootstrap_values will be ignored") - else: - strategies.insert(0, DataSource.BOOTSTRAP) - if self._options.fallback_to_statsig_api: - strategies.append(DataSource.STATSIG_NETWORK) - - return strategies + strategies.insert(0, DataSource.DATASTORE) + if self._options.bootstrap_values: + if data_store is not None: + globals.logger.debug("data_store gets priority over bootstrap_values. bootstrap_values will be ignored") + else: + strategies.insert(0, DataSource.BOOTSTRAP) + if self._options.fallback_to_statsig_api: + strategies.append(DataSource.STATSIG_NETWORK) + + return strategies + except Exception: + globals.logger.warning( + "Failed to get initialization sources, fallling back to always sync from statsig network " + ) + return [DataSource.STATSIG_NETWORK] diff --git a/statsig/spec_updater.py b/statsig/spec_updater.py index 68f2634..affe611 100644 --- a/statsig/spec_updater.py +++ b/statsig/spec_updater.py @@ -413,19 +413,25 @@ def _sync(self, sync_func, interval, fast_start=False): self._error_boundary.log_exception("_sync", e) def _get_sync_dcs_strategies(self) -> List[DataSource]: - if self._options.config_sync_sources is not None: - return self._options.config_sync_sources - strategies = [DataSource.NETWORK] - if ( - self._options.data_store is not None - and self._options.data_store.should_be_used_for_querying_updates( - STORAGE_ADAPTER_KEY - ) - ): - strategies = [DataSource.DATASTORE] - if self._options.fallback_to_statsig_api: - strategies.append(DataSource.STATSIG_NETWORK) - return strategies + try: + if self._options.config_sync_sources is not None: + return self._options.config_sync_sources + strategies = [DataSource.NETWORK] + if ( + self._options.data_store is not None + and self._options.data_store.should_be_used_for_querying_updates( + STORAGE_ADAPTER_KEY + ) + ): + strategies = [DataSource.DATASTORE] + if self._options.fallback_to_statsig_api: + strategies.append(DataSource.STATSIG_NETWORK) + return strategies + except Exception: + globals.logger.warning( + "Failed to get sync sources, fallling back to always sync from statsig network " + ) + return [DataSource.STATSIG_NETWORK] def shutdown(self): if self._background_download_configs is not None: