-
Notifications
You must be signed in to change notification settings - Fork 7
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
Initial Streaming Implementation #232
Conversation
secret: string; | ||
|
||
/** | ||
* Controls what Javascript type to deserialize {@link https://fqlx-beta--fauna-docs.netlify.app/fqlx/beta/reference/language/types#long | Fauna longs} to. |
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.
This link returns a 404 to me.
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.
Ah. Looks like all of the links should be updated!
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.
one thing I wonder, and we could always wait and see if people want this, but would it be worth in addition to our two step
1 - create stream token
2 - call stream
to also add an API in the drivers that allowed
client.stream(fql'query here that produces a stream').on( event => ..)
purely as a form of convenience. Under the hood we'd still send the same queries.
I think it's a good idea. |
I've implemented this. |
I've updated error handling, so that retry-able network errors create events which can be handled. In the event of a retry, the user should expect at least two events back-to-back:
|
Does that mean that drivers are syntactically producing error events that mimic events from the server? If so, are driver errors distinguishable from stream error events? I'm concerned that if we are co-opting the event format we can end up in a situation where a new error event in the server shadows a driver specific event. Ideally we would want to keep these dimensions separate so we don't have to check every driver before introducing new error codes in the server. |
06d5da6
to
3888409
Compare
@pnwpedro I've rebased on main to include the concourse pipeline changes, and this PR is now set to merge into the |
Ticket(s): FE-4969
This is an initial go at implementing streaming events for the v10 API. Anything here is up for review and comment.
Problem
Implement the v10 Fauna streaming API
We need to support browsers and Node. We would also like to support other runtimes if possible.
Solution
Provide a
StreamClient
class which provides the primary user interface to establish a stream and handle events.Provide a lower-level
HTTPStreamClient
interface that can be implemented for different environments.The
StreamClient
contains an instance of anHTTPStreamClient
, which mirrors the existing lower-levelHTTPClient
interface that enables different backend implementations for theClient
class.The
HTTPStreamClient
is responsible for initiating a request and returning an object that implements theStreamAdapter
interface. TheStreamAdapter
contains an asyncronous generator function that yields Fauna streaming events as raw strings for theStreamClient
to use. TheStreamAdapter
also provides aclose
method to provide a mechanism to close the stream.The
StreamClient
is responsible for parsing the raw-string events into valid types. Streaming events always return data in the "tagged" format. TheStreamClient
must be configured with how to handle decoding ofLong
types.An instance of
StreamClient
is created on each call toClient.stream
. Each instance tracks it's own handlers for events. The underlying HTTP connections should be reused when possible.Result
Streams can be used in the browser and Node.js.
This does not work in public Fauna environments or the docker image yet.
Usage
Two ways to use the stream are enabled:
Async Iterator example
Callbacks example
The driver will take care of the initial request to convert to a stream if you provide a Query
Error handling
The driver tries to reestablish streaming connections when there are network errors. With current defaults, retries start quickly but have exponential backoff, capped at 10s, and will continue trying to reestablish for about 10 minutes. That's generous enough to let your internet connection drop and come back.
Network errors are hidden from the user while retries are still being attempted
Errors from Fauna are assumed fatal. Any error events coming from Fauna will cause an error to be thrown.
Out of scope
N/A
Testing
tests have been added and can be run on the most recent docker image using
yarn test
.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.