feat: use sse for workspace page#4122
Conversation
|
If SSE fails and we're in the |
|
How should we handle SSE errors? Should the page show something about failing to refresh data? Maybe a warning-style thing rather than error-style, like when your workspace is going to stop soon? |
The backend will close the connection when we get a non-recoverable error. My first thought is to console log the errors we get or something low-stakes like that, and just keep it open unless the backend closes it. A non-fatal error may be a momentary db issue, but the next message may come through fine. On the connection being closed we should retry, probably with a backoff. |
@presleyp good catch; this should be fixed.
@presleyp Right now, SSE errors will not block the user from viewing the page. I will put up a subsequent PR with a new, warning style message indicating workspace data might not be up to date if that field is populated. I want to handle that separately because there are several workspace error cleanup items to tackle and it would be nice to have them all in 1 PR.
@f0ssel Yeah, we should add a backoff. Right now, we close, wait a second and then try again with a new connection. I would like to add that backoff when I add the warning described above. |
presleyp
left a comment
There was a problem hiding this comment.
Sorry, I could've sworn I got this review in last night!
resolves #4058
Based on @f0ssel's implementation of SSE on the BE, we are now using SSE on the FE to get workspace and resource updates (instead of polling).
Background
Previously, we fetched a workspace, template, and permissions, and then we started two separate polling states: we polled for workspace, and we polled for resources.
Since @f0ssel's implementation returns both workspace and resources in one object, we are able to simplify.
Now: we fetch a workspace, template, and permissions, and then we initialize an
EventSourcethat returns workspace and workspace-related data as the server updates the client.To Test
Pull down the branch and open a workspace; make sure the workspace and resources load.

Open Chrome inspect and check out the network tab: you should be able to see a watch request that shows events streaming in: