Skip to content

Commit

Permalink
more try catch on initialization path (#338)
Browse files Browse the repository at this point in the history
Add more try catch logic
  • Loading branch information
xinlili-statsig authored Oct 7, 2024
1 parent 9c1a5bd commit 94e5c44
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
34 changes: 20 additions & 14 deletions statsig/spec_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
32 changes: 19 additions & 13 deletions statsig/spec_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 94e5c44

Please sign in to comment.