All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.kestra.jdbc.runner.AbstractJdbcExecutorStateStorage Maven / Gradle / Ivy

The newest version!
package io.kestra.jdbc.runner;

import io.kestra.core.models.executions.Execution;
import io.kestra.core.runners.ExecutorState;
import io.kestra.jdbc.repository.AbstractJdbcRepository;
import org.jooq.DSLContext;
import org.jooq.Field;
import org.jooq.Record1;
import org.jooq.SelectConditionStep;

import java.util.Map;

public abstract class AbstractJdbcExecutorStateStorage {
    protected io.kestra.jdbc.AbstractJdbcRepository jdbcRepository;

    public AbstractJdbcExecutorStateStorage(io.kestra.jdbc.AbstractJdbcRepository jdbcRepository) {
        this.jdbcRepository = jdbcRepository;
    }

    public ExecutorState get(DSLContext dslContext, Execution execution) {
        SelectConditionStep> select = dslContext
            .select(AbstractJdbcRepository.field("value"))
            .from(this.jdbcRepository.getTable())
            .where(
                AbstractJdbcRepository.field("key").eq(execution.getId())
            );

        return this.jdbcRepository.fetchOne(select)
            .orElse(new ExecutorState(execution.getId()));
    }

    public void save(DSLContext dslContext, ExecutorState executorState) {
        Map, Object> fields = this.jdbcRepository.persistFields(executorState);
        this.jdbcRepository.persist(executorState, dslContext, fields);
    }

    public void delete(Execution execution) {
        this.jdbcRepository.delete(new ExecutorState(execution.getId()));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy