Skip to content

Commit

Permalink
Fix last view value of agent card component
Browse files Browse the repository at this point in the history
  • Loading branch information
noreplydev committed Nov 4, 2024
1 parent b13449b commit a5662e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions packages/protolib/src/bundles/agents/agents/agentsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ const AgentCard = ({ data, extraMenuActions }) => {
online: false,
last_view: null
})

useEffect(() => {
const setNewStatus = async () => {
const statusResult = await getAgentStatus(data.name)
setStatus(statusResult.status)
}

setNewStatus()
const interval = setInterval(setNewStatus, 5000)

return () => clearInterval(interval)
}, [])

const getAgentStatus = async (agentName) => {
const response = await API.get(`${sourceUrl}/${agentName}/status`)
if (!response.data) return {
Expand All @@ -110,16 +123,6 @@ const AgentCard = ({ data, extraMenuActions }) => {
return `${hours}:${minutes} ${day}/${month}/${year}`;
}


useEffect(() => {
const interval = setInterval(async () => {
const statusResult = await getAgentStatus(data.name)
setStatus(statusResult.status)
}, 5000)

return () => clearInterval(interval)
}, [])

return <CardBody title={data.name}>
<XStack right={20} top={20} position={"absolute"}>
<ItemMenu type="item" sourceUrl={sourceUrl} onDelete={async (sourceUrl, deviceId?: string) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const heartbeatTimeout = 15_000 // 30 seconds
export const heartbeatTimeout = 30_000 // 30 seconds
export const defActionEndpoint = (agentName: string, subsystemName: string, actionName: string) => `agents/${agentName}/subsystem/${subsystemName}/action/${actionName}`
export const defMonitorEndpoint = (agentName: string, subsystemName: string, monitorName: string) => `agents/${agentName}/subsystem/${subsystemName}/monitor/${monitorName}`

0 comments on commit a5662e9

Please sign in to comment.