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

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

There is a newer version: 0.19.11
Show newest version
package io.kestra.jdbc.runner;

import io.kestra.core.runners.ExecutionDelay;
import io.kestra.jdbc.repository.AbstractJdbcRepository;
import org.jooq.Field;
import org.jooq.Record1;
import org.jooq.SelectConditionStep;
import org.jooq.impl.DSL;

import java.time.ZonedDateTime;
import java.util.Map;
import java.util.function.Consumer;

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

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

    public void get(Consumer consumer) {
        ZonedDateTime now = ZonedDateTime.now();

        this.jdbcRepository
            .getDslContextWrapper()
            .transaction(configuration -> {
                SelectConditionStep> select = DSL
                    .using(configuration)
                    .select(AbstractJdbcRepository.field("value"))
                    .from(this.jdbcRepository.getTable())
                    .where(
                        AbstractJdbcRepository.field("date").lessOrEqual(now.toOffsetDateTime())
                    );

                this.jdbcRepository.fetch(select)
                    .forEach(executionDelay -> {
                        consumer.accept(executionDelay);
                        jdbcRepository.delete(executionDelay);
                    });
            });
    }

    public void save(ExecutionDelay executionDelay) {
        Map, Object> fields = this.jdbcRepository.persistFields(executionDelay);
        this.jdbcRepository.persist(executionDelay, fields);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy