Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: tolerate disconnects in agent metadata frontend
  • Loading branch information
ammario committed Mar 31, 2023
commit f9521ba31e664cf394780a03eb862189ba33a3e5
31 changes: 21 additions & 10 deletions site/src/components/Resources/AgentMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,18 +241,29 @@ export const AgentMetadata: FC<{
setMetadata(storybookMetadata)
return
}
const source = watchAgentMetadata(agent.id)

source.onerror = (e) => {
console.error("received error in watch stream", e)
}
source.addEventListener("data", (e) => {
const data = JSON.parse(e.data)
setMetadata(data)
})
return () => {
source.close()
const connect = (): (() => void) => {
const source = watchAgentMetadata(agent.id)

source.onerror = (e) => {
console.error("received error in watch stream", e)
setMetadata(undefined)
source.close()

setTimeout(() => {
connect()
}, 3000)
}

source.addEventListener("data", (e) => {
const data = JSON.parse(e.data)
setMetadata(data)
})
return () => {
source.close()
}
}
return connect()
}, [agent.id, watchAgentMetadata, storybookMetadata])

if (metadata === undefined) {
Expand Down