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

23 wiersze
758 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-18 11:32:25 +00:00
export const fetchNodeToProcess = async (
elastic: ElasticClient
): Promise<Node> => {
2022-09-14 19:16:04 +00:00
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
}