io.kestra.jdbc.runner.AbstractJdbcExecutorStateStorage Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jdbc Show documentation
Show all versions of jdbc Show documentation
The modern, scalable orchestrator & scheduler open source platform
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()));
}
}