public ProcessingNodesState calculateProcessingState(TimeRange timeRange) {
        final DateTime updateThresholdTimestamp = clock.nowUTC().minus(updateThreshold.toMilliseconds());

        try (DBCursor<ProcessingStatusDto> statusCursor = db.find(activeNodes(updateThresholdTimestamp))) {
            if (!statusCursor.hasNext()) {
                return ProcessingNodesState.NONE_ACTIVE;
            }

            int activeNodes = 0;
            int idleNodes = 0;
            while (statusCursor.hasNext()) {
                activeNodes++;
                ProcessingStatusDto nodeProcessingStatus = statusCursor.next();
                DateTime lastIndexedMessage = nodeProcessingStatus.receiveTimes().postIndexing();
                // If node is behind and is busy, it is overloaded.
                if (lastIndexedMessage.isBefore(timeRange.getTo()) && isBusy(nodeProcessingStatus)) {
                    return ProcessingNodesState.SOME_OVERLOADED;
                }
                // If a node did not index a message that is at least at the start of the time range,
                // we consider it idle.
                if (lastIndexedMessage.isBefore(timeRange.getFrom())) {
                    idleNodes++;
                }
            }

            // Only if all nodes are idle, we stop the processing.
            if (activeNodes == idleNodes) {
                return ProcessingNodesState.ALL_IDLE;
            }
        }

        // If none of the above checks return, we can assume that some nodes have already indexed the given timerange.
        return ProcessingNodesState.SOME_UP_TO_DATE;
    }
@Test
    @MongoDBFixtures("processing-status-idle-nodes.json")
    public void processingStateIdleNodesWhereLastMessageWithinTimeRange() {
        when(clock.nowUTC()).thenReturn(DateTime.parse("2019-01-01T04:00:00.000Z"));
        when(updateThreshold.toMilliseconds()).thenReturn(Duration.hours(1).toMilliseconds());

        TimeRange timeRange = AbsoluteRange.create("2019-01-01T02:00:00.000Z", "2019-01-01T03:00:00.000Z");
        assertThat(dbService.calculateProcessingState(timeRange)).isEqualTo(ProcessingNodesState.SOME_UP_TO_DATE);
    }