forked from connext/subgraph-cache-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcronHandler.ts
More file actions
61 lines (57 loc) · 2.02 KB
/
cronHandler.ts
File metadata and controls
61 lines (57 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { SubgraphHealth, getSubgraphHealth, Healths } from './manualDeps'
export const getSubgraphName = (url: string):string => {
const split = url.split('/')
return split[split.length - 1]
}
export async function getCrosschainHealth(): Promise<Healths | void> {
const healthsByChainId: Healths = {}
const chainDataRes = await fetch(
'https://raw.githubusercontent.com/Auromony/chaindata/main/crossChain.json',
)
const chainData: any = await chainDataRes.json()
console.log('chainData: ', JSON.stringify(chainData))
await Promise.all(
chainData.map(async (chain: { chainId: number; subgraph: string[] }) => {
const subgraphUrls = chain.subgraph
console.log(`ChainID: ${chain.chainId}: SubgraphURL ${subgraphUrls}`)
if (subgraphUrls === undefined) {
console.log(`no configured subgraphs for this chain`)
return (healthsByChainId[chain.chainId] = JSON.stringify({
data: undefined,
}))
}
if (subgraphUrls) {
//statues for all urls
const urlStatuses: SubgraphHealth[] = []
await Promise.all(
subgraphUrls.map(async (subgraphUrl: string) => {
try {
console.log(getSubgraphName(subgraphUrl));
const status = await getSubgraphHealth(
getSubgraphName(subgraphUrl),
subgraphUrl,
)
if (status) {
status.url = subgraphUrl
urlStatuses.push(status)
}
} catch (err) {
console.error(
`Error getting health for subgraph ${getSubgraphName(subgraphUrl)}: `,
err,
)
}
healthsByChainId[chain.chainId] = JSON.stringify(urlStatuses)
}),
)
}
}),
)
return healthsByChainId
}
export async function handleCronJob(): Promise<void> {
const healths = await getCrosschainHealth()
console.log(JSON.stringify(healths));
//@ts-ignore
await HEALTHS.put('health', JSON.stringify(healths))
}