fedicrawl/application/src/Storage/Nodes/setNodeStats.ts

27 wiersze
747 B
TypeScript
Czysty Zwykły widok Historia

2022-09-14 19:16:04 +00:00
import { ElasticClient } from '../ElasticClient'
import nodeIndex from '../Definitions/nodeIndex'
import Node from '../Definitions/Node'
import getNode from './getNode'
import { NodeStats } from '../../Jobs/Nodes/updateNodeFeedStats'
2022-09-18 11:32:25 +00:00
import assertDefined from '../assertDefined'
2022-09-14 19:16:04 +00:00
2022-09-18 11:32:25 +00:00
export const setNodeStats = async (
elastic: ElasticClient,
node: Node,
stats: NodeStats
): Promise<Node> => {
2022-09-14 19:16:04 +00:00
console.info('Setting node stats', { domain: node.domain, stats })
await elastic.update<Node>({
index: nodeIndex,
id: node.domain,
doc: {
accountFeedCount: stats.account,
channelFeedCount: stats.channel
}
})
2022-09-18 11:32:25 +00:00
return assertDefined(
await getNode(elastic, node.domain),
'Missing node after updating it'
)
2022-09-14 19:16:04 +00:00
}