Skip to content
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

Implement Real-Time Functionality #61

Closed
matthewelwell opened this issue Sep 11, 2023 · 1 comment · Fixed by #73
Closed

Implement Real-Time Functionality #61

matthewelwell opened this issue Sep 11, 2023 · 1 comment · Fixed by #73
Assignees

Comments

@matthewelwell
Copy link
Contributor

matthewelwell commented Sep 11, 2023

The Python client should support our real-time functionality via SSE. When using local evaluation mode, the client should listen for events on the stream and update its local cache of data if the value if the value of updated_at that was provided in the stream message is more recent than the last one received (and stored) from the X-Flagsmith-Document-Updated-At header received from the relevant API endpoint.

We should start by implementing this for local evaluation, since we already maintain a local cache of the environment document in this instance.

With regards to remote evaluation modes, we will need to implement a caching interface that stores the Flags class from the latest response from the relevant endpoint, and retrieves the flags again if it receives an event on the SSE stream. For now, this cache interface only needs to support a local memory cache, but we should make the interface generic to support other options.

@matthewelwell
Copy link
Contributor Author

Thinking something like this:

# define use_stream (or similar) in the __init__ method on the client. 

def connect(self)
    while self.use_stream:
        try: 
            stream = requests.GET(stream_url, stream=True)
            
        except requests.ConnectionError:
            reconnect()

bne added a commit that referenced this issue Jan 17, 2024
@bne bne linked a pull request Jan 17, 2024 that will close this issue
matthewelwell pushed a commit that referenced this issue Feb 6, 2024
* #61 SSE streaming manager

* Remove extraneous import

* isort fixes

* Self CR

* CR changes

* Simplify Flagsmith.__init__ to keep flake8 happy

* Remove extraneous noqa

* Adds typing to new methods and tests

* Remove typing.TypeAlias

Incompatible with python <= 3.9

* Use Optional as opposed to pipe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants