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

21 wiersze
754 B
TypeScript
Czysty Zwykły widok Historia

import { NoNodeFoundError } from './NoNodeFoundError'
2022-09-14 19:16:04 +00:00
import findNotProcessedNodeWithAttemptLimit from './findNotProcessedNodeWithAttemptLimit'
import findNodeWithOldestRefreshWithLimits from './findNodeWithOldestRefreshWithLimits'
import Node from '../Definitions/Node'
import { ElasticClient } from '../ElasticClient'
import nodeIndex from '../Definitions/nodeIndex'
2021-12-23 14:14:06 +00:00
2022-09-14 19:16:04 +00:00
export const fetchNodeToProcess = async (elastic: ElasticClient): Promise<Node> => {
await elastic.indices.refresh({ index: nodeIndex })
let node = await findNotProcessedNodeWithAttemptLimit(elastic)
if (node !== null) {
return node
2021-12-23 14:14:06 +00:00
}
2022-09-14 19:16:04 +00:00
node = await findNodeWithOldestRefreshWithLimits(elastic)
if (node !== null) {
return node
2021-12-23 14:14:06 +00:00
}
2022-09-14 19:16:04 +00:00
throw new NoNodeFoundError()
2021-12-23 14:14:06 +00:00
}