-
Notifications
You must be signed in to change notification settings - Fork 2
feat: support realtime toggle update via socket.io #20
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
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cb45ad6
feat: support realtime toggle update via socket.io
hezean 4748472
chore: add license header(s)
hezean ccdf233
style: format python code (pep8)
hezean 6fb507a
revert black format single quotation
hezean 6a36971
style: format python code (pep8)
hezean e70c713
sync
hezean 0ff0dd6
chore: add license header(s)
hezean 0169e0f
style: format python code (pep8)
hezean 6a68edd
sync
hezean 95728ab
style: format python code (pep8)
hezean f9f33c1
finish
hezean bdff2a8
style: format python code (pep8)
hezean b718a67
fix python3.5 mock socketio clientnamespace
hezean 528e0a5
remove unnecessary changes
hezean 9a2981f
add it
hezean 8565c11
style: format python code (pep8)
hezean File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2022 FeatureProbe | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import warnings | ||
|
||
|
||
def _nameof(anything): | ||
if callable(anything): | ||
return "function<{}>".format(anything.__name__) | ||
elif isinstance(anything, property): | ||
return "property<{}>".format(anything.fget.__name__) | ||
# TODO: add more type support | ||
else: | ||
return None | ||
|
||
|
||
def deprecated(*, since: str = None, successor=None): | ||
"""Marks functions as deprecated.""" | ||
|
||
def wrapper(func): | ||
def inner(*args, **kwargs): | ||
successor_name = _nameof(successor) | ||
warnings.warn( | ||
"{} is deprecated{}{}".format( | ||
_nameof(func), | ||
" since " + since if since is not None else "", | ||
", consider using {} instead.".format(successor_name) | ||
if successor_name is not None | ||
else "", | ||
), | ||
category=DeprecationWarning, | ||
stacklevel=2, | ||
) | ||
return func(*args, **kwargs) | ||
|
||
return inner | ||
|
||
return wrapper |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2022 FeatureProbe | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import logging | ||
|
||
from sys import version_info as python_version | ||
if python_version >= (3, 6): | ||
from socketio import ClientNamespace | ||
else: | ||
class ClientNamespace: | ||
def __init__(self, namespace=None): | ||
... | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from featureprobe.context import Context | ||
from featureprobe.synchronizer import Synchronizer | ||
|
||
|
||
class RealtimeToggleUpdateNS(ClientNamespace): | ||
__logger = logging.getLogger("FeatureProbe-Socket") | ||
|
||
def __init__( | ||
self, | ||
namespace, | ||
context: "Context", | ||
synchronizer: "Synchronizer"): | ||
super(RealtimeToggleUpdateNS, self).__init__(namespace=namespace) | ||
self._synchronizer = synchronizer | ||
self._sdk_key = context.sdk_key | ||
|
||
def on_connect(self): | ||
self.__logger.info("connect socketio success") | ||
self.emit("register", {"key": self._sdk_key}) | ||
|
||
def on_connect_error(self, error): | ||
self.__logger.error("socketio error: {}".format(error)) | ||
|
||
def on_disconnect(self): | ||
self.__logger.info("disconnecting socketio") | ||
|
||
def on_update(self, data): | ||
self.__logger.info("socketio recv update event") | ||
self._synchronizer.sync() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
not used in this pr, but it may be used someday, so keep it?