Search in sources :

Example 1 with ExecutionState

use of com.bakdata.conquery.models.execution.ExecutionState in project conquery by bakdata.

the class QueryProcessor method tryReuse.

/**
 * Determine if the submitted query does reuse ONLY another query and restart that instead of creating another one.
 */
private ManagedExecution<?> tryReuse(QueryDescription query, ManagedExecutionId executionId, DatasetRegistry datasetRegistry, ConqueryConfig config, ExecutionManager executionManager, User user) {
    ManagedExecution<?> execution = datasetRegistry.getMetaRegistry().resolve(executionId);
    if (execution == null) {
        return null;
    }
    // Direct reuse only works if the queries are of the same type (As reuse reconstructs the Query for different types)
    if (!query.getClass().equals(execution.getSubmitted().getClass())) {
        return null;
    }
    // If SecondaryIds differ from selected and prior, we cannot reuse them.
    if (query instanceof SecondaryIdQuery) {
        final SecondaryIdDescription selectedSecondaryId = ((SecondaryIdQuery) query).getSecondaryId();
        final SecondaryIdDescription reusedSecondaryId = ((SecondaryIdQuery) execution.getSubmitted()).getSecondaryId();
        if (!selectedSecondaryId.equals(reusedSecondaryId)) {
            return null;
        }
    }
    // If the user is not the owner of the execution, we definitely create a new Execution, so the owner can cancel it
    if (!user.isOwner(execution)) {
        final ManagedExecution<?> newExecution = executionManager.createExecution(datasetRegistry, execution.getSubmitted(), user, execution.getDataset());
        newExecution.setLabel(execution.getLabel());
        newExecution.setTags(execution.getTags().clone());
        storage.updateExecution(newExecution);
        execution = newExecution;
    }
    ExecutionState state = execution.getState();
    if (state.equals(ExecutionState.RUNNING)) {
        log.trace("The Execution[{}] was already started and its state is: {}", execution.getId(), state);
        return execution;
    }
    log.trace("Re-executing Query {}", execution);
    executionManager.execute(datasetRegistry, execution, config);
    return execution;
}
Also used : ExecutionState(com.bakdata.conquery.models.execution.ExecutionState) SecondaryIdQuery(com.bakdata.conquery.apiv1.query.SecondaryIdQuery) SecondaryIdDescription(com.bakdata.conquery.models.datasets.SecondaryIdDescription)

Aggregations

SecondaryIdQuery (com.bakdata.conquery.apiv1.query.SecondaryIdQuery)1 SecondaryIdDescription (com.bakdata.conquery.models.datasets.SecondaryIdDescription)1 ExecutionState (com.bakdata.conquery.models.execution.ExecutionState)1