Skip to content

Commit

Permalink
feat: health check for provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephyruso authored and Zephyruso committed Aug 31, 2023
1 parent b4fc1b4 commit 03dda3c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
34 changes: 24 additions & 10 deletions src/pages/Proxies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default () => {
updateProxy,
setProxyGroupByProxyName,
delayTestByProxyGroupName,
updateProxyProviderByProviderName,
updateProviderByProviderName,
healthCheckByProviderName,
} = useProxies()

const [collapsedMap, setCollapsedMap] = createSignal<Record<string, boolean>>(
Expand All @@ -33,9 +34,14 @@ export default () => {
delayTestByProxyGroupName(name)
}

const onHealthCheckClick = (e: MouseEvent, name: string) => {
e.stopPropagation()
healthCheckByProviderName(name)
}

const onUpdateProviderClick = (e: MouseEvent, name: string) => {
e.stopPropagation()
updateProxyProviderByProviderName(name)
updateProviderByProviderName(name)
}

return (
Expand Down Expand Up @@ -112,14 +118,22 @@ export default () => {
</div>
</div>

<button
class="btn btn-circle btn-sm"
onClick={(e) =>
onUpdateProviderClick(e, proxyProvider.name)
}
>
<IconReload />
</button>
<div>
<button
class="btn btn-circle btn-sm mr-2"
onClick={(e) =>
onUpdateProviderClick(e, proxyProvider.name)
}
>
<IconReload />
</button>
<button
class="btn btn-circle btn-sm"
onClick={(e) => onHealthCheckClick(e, proxyProvider.name)}
>
<IconBrandSpeedtest />
</button>
</div>
</div>
)
const content = (
Expand Down
21 changes: 11 additions & 10 deletions src/signals/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ export function useProxies() {
`group/${proxyGroupName}/delay?url=https%3A%2F%2Fwww.gstatic.com%2Fgenerate_204&timeout=2000`,
)
.json()
const dMap = delayMap()

Object.entries(data).forEach(([name, time]) => {
dMap[name] = time
})
setDelayMap({ ...delayMap(), ...data })
}

setDelayMap({ ...dMap })
const updateProviderByProviderName = async (proxyProviderName: string) => {
await request.put(`providers/proxies/${proxyProviderName}`)
await updateProxy()
}

const updateProxyProviderByProviderName = async (
proxyProviderName: string,
) => {
await request.put(`/providers/proxies/${proxyProviderName}`)
const healthCheckByProviderName = async (providerName: string) => {
await request.get(`providers/proxies/${providerName}/healthcheck`, {
timeout: 30 * 1000, // thie api was a little bit slow sometimes...
})
await updateProxy()
}

Expand All @@ -89,6 +89,7 @@ export function useProxies() {
delayMap,
updateProxy,
setProxyGroupByProxyName,
updateProxyProviderByProviderName,
updateProviderByProviderName,
healthCheckByProviderName,
}
}

0 comments on commit 03dda3c

Please sign in to comment.