Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 48
feat: Add async FDv2 data sources#485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
1d9f3df565b4376a237d869f2f1a9616eba161bb0fFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,7 +3,6 @@ | ||
| from ldclient.impl.dependency_tracker import DependencyTracker, KindAndKey | ||
| from ldclient.impl.listeners import Listeners | ||
| from ldclient.impl.rwlock import ReadWriteLock | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The locks are not always needed in async python unless you are doing multiple awaits between the values you want to keep consistent which we are not doing here. It was over eager and trying to match sync too much. | ||
| from ldclient.interfaces import ( | ||
| AsyncDataSourceUpdateSink, | ||
| AsyncFeatureStore, | ||
| @@ -23,13 +22,11 @@ def __init__(self, store: AsyncFeatureStore, status_listeners: Listeners, flag_c | ||
| self.__flag_change_listeners = flag_change_listeners | ||
| self.__tracker = DependencyTracker() | ||
| self.__lock = ReadWriteLock() | ||
| self.__status = DataSourceStatus(DataSourceState.INITIALIZING, time.time(), None) | ||
| @property | ||
| def status(self) -> DataSourceStatus: | ||
| with self.__lock.read(): | ||
| return self.__status | ||
| return self.__status | ||
| async def init(self, all_data: Mapping[VersionedDataKind, Mapping[str, dict]]) -> None: | ||
| old_data: Optional[Dict[VersionedDataKind, Mapping[str, dict]]] = None | ||
| @@ -73,22 +70,21 @@ async def delete(self, kind: VersionedDataKind, key: str, version: int) -> None: | ||
| def update_status(self, new_state: DataSourceState, new_error: Optional[DataSourceErrorInfo]) -> None: | ||
| status_to_broadcast = None | ||
| with self.__lock.write(): | ||
| old_status = self.__status | ||
| old_status = self.__status | ||
| if new_state == DataSourceState.INTERRUPTED and old_status.state == DataSourceState.INITIALIZING: | ||
| new_state = DataSourceState.INITIALIZING | ||
| if new_state == DataSourceState.INTERRUPTED and old_status.state == DataSourceState.INITIALIZING: | ||
| new_state = DataSourceState.INITIALIZING | ||
| if new_state == old_status.state and new_error is None: | ||
| return | ||
| if new_state == old_status.state and new_error is None: | ||
| return | ||
| self.__status = DataSourceStatus( | ||
| new_state, | ||
| self.__status.since if new_state == self.__status.state else time.time(), | ||
| self.__status.error if new_error is None else new_error, | ||
| ) | ||
| self.__status = DataSourceStatus( | ||
| new_state, | ||
| self.__status.since if new_state == self.__status.state else time.time(), | ||
| self.__status.error if new_error is None else new_error, | ||
| ) | ||
| status_to_broadcast = self.__status | ||
| status_to_broadcast = self.__status | ||
| if status_to_broadcast is not None: | ||
| self.__status_listeners.notify(status_to_broadcast) | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to catch and raise here, it isn't caught by Exception so this was just extra code.