Skip to content

Commit

Permalink
Chore: use SDK for health metrics and add error handling to homestar …
Browse files Browse the repository at this point in the history
…client getter
  • Loading branch information
avivash committed Nov 16, 2023
1 parent 85b2fc4 commit beb3105
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 59 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
]
},
"dependencies": {
"@fission-codes/homestar": "^0.6.0",
"@fission-codes/homestar": "^0.6.1",
"@oddjs/odd": "0.37.0",
"@open-rpc/client-js": "^1.8.1",
"@types/three": "^0.156.0",
Expand Down
7 changes: 4 additions & 3 deletions src/components/settings/NodeInfo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import clipboardCopy from 'clipboard-copy'
import { onDestroy, onMount } from 'svelte'
import { requestHealth } from '$lib/health'
import { addNotification } from '$lib/notifications'
import { getHomestarClient } from '$lib/rpc'
import ClipboardIcon from '$components/icons/ClipboardIcon.svelte'
export let compressedView = false
Expand All @@ -17,12 +17,13 @@
}
onMount(async () => {
health = await requestHealth()
const homestar = getHomestarClient()
health = (await homestar.health()).result
// Poll until listener addresses are returned
if (!health?.nodeInfo?.dynamic?.listeners?.length) {
interval = setInterval(async () => {
health = await requestHealth()
health = (await homestar.health()).result
if (health?.nodeInfo?.dynamic?.listeners?.length) {
clearInterval(interval)
}
Expand Down
37 changes: 0 additions & 37 deletions src/lib/health.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/lib/metrics.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import type { InferError } from '@fission-codes/homestar/types'

import { homestar } from '$lib/rpc'
import { getHomestarClient } from '$lib/rpc'

type Metric = {
data: Data[]
Expand All @@ -17,6 +17,7 @@ type Data = {

export const requestMetrics = async (): Promise<Metric> => {
try {
const homestar = getHomestarClient()
const { error, result } = await homestar.metrics()
if (error) {
throw new Error(error)
Expand Down
4 changes: 3 additions & 1 deletion src/lib/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// import { WebSocket } from 'unws'

import { networkStore } from '$lib/stores'
import { homestar } from '$lib/rpc'
import { getHomestarClient } from '$lib/rpc'

export type NetworkStore = {
loading: boolean
Expand Down Expand Up @@ -34,6 +34,8 @@ const RECEIPT_SENT = 'network:publishedReceiptPubsub'
// })

export const subscribNetworkEvents = async (): Promise<void> => {
const homestar = getHomestarClient()

await homestar.networkEvents(res => {
// console.log('node1 res', res)
if (res.error) {
Expand Down
29 changes: 21 additions & 8 deletions src/lib/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,35 @@ import {
Client,
WebSocketTransport as OpenRPCWebSocketTransport
} from '@open-rpc/client-js'
import { addNotification } from './notifications'

const openRPCTransport = new OpenRPCWebSocketTransport(
import.meta.env.VITE_WEBSOCKET_ENDPOINT
)
const requestManager = new RequestManager([openRPCTransport])
export const rpcClient = new Client(requestManager)

const transport = new WebsocketTransport(
import.meta.env.VITE_WEBSOCKET_ENDPOINT,
{
ws: WebSocket
let homestar
export const getHomestarClient = () => {
try {
if (!homestar) {
const transport = new WebsocketTransport(
import.meta.env.VITE_WEBSOCKET_ENDPOINT,
{
ws: WebSocket
}
) // WS
homestar = new Homestar({
transport
})
}

return homestar
} catch (error) {
console.error(error)
addNotification(error, 'error')
}
) // WS
export const homestar = new Homestar({
transport,
})
}

/**
* Subscribe to WS messages and pass the data to the appropriate handler
Expand Down
4 changes: 3 additions & 1 deletion src/lib/workflows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { get as getStore } from 'svelte/store'

import type { Receipt, FunctionOperation, Meta } from '$lib/functions'
import { addNotification } from '$lib/notifications'
import { homestar } from '$lib/rpc'
import { getHomestarClient } from '$lib/rpc'
import { workflowsStore } from '$lib/stores'

export type WorkflowsStore = {
Expand Down Expand Up @@ -213,6 +213,8 @@ export const runWorkflow = async (
}
})

const homestar = getHomestarClient()

await homestar.runWorkflow(
{ ...payloadToRun, name: runName },
async data => {
Expand Down

0 comments on commit beb3105

Please sign in to comment.