-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jdbc): add support for executor delayed
- Loading branch information
1 parent
98f529a
commit 63aab8f
Showing
17 changed files
with
349 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
jdbc-mysql/src/main/java/io/kestra/runner/mysql/MysqlExecutionDelayStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.kestra.runner.mysql; | ||
|
||
import io.kestra.core.runners.ExecutionDelay; | ||
import io.kestra.jdbc.runner.AbstractExecutionDelayStorage; | ||
import io.kestra.repository.mysql.MysqlRepository; | ||
import io.micronaut.context.ApplicationContext; | ||
import jakarta.inject.Singleton; | ||
|
||
@Singleton | ||
@MysqlQueueEnabled | ||
public class MysqlExecutionDelayStorage extends AbstractExecutionDelayStorage { | ||
public MysqlExecutionDelayStorage(ApplicationContext applicationContext) { | ||
super(new MysqlRepository<>(ExecutionDelay.class, applicationContext)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
jdbc-postgres/src/main/java/io/kestra/runner/postgres/PostgresExecutionDelayStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.kestra.runner.postgres; | ||
|
||
import io.kestra.core.runners.ExecutionDelay; | ||
import io.kestra.jdbc.runner.AbstractExecutionDelayStorage; | ||
import io.kestra.repository.postgres.PostgresRepository; | ||
import io.micronaut.context.ApplicationContext; | ||
import jakarta.inject.Singleton; | ||
|
||
@Singleton | ||
@PostgresQueueEnabled | ||
public class PostgresExecutionDelayStorage extends AbstractExecutionDelayStorage { | ||
public PostgresExecutionDelayStorage(ApplicationContext applicationContext) { | ||
super(new PostgresRepository<>(ExecutionDelay.class, applicationContext)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
jdbc/src/main/java/io/kestra/jdbc/runner/AbstractExecutionDelayStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.kestra.jdbc.runner; | ||
|
||
import io.kestra.core.runners.ExecutionDelay; | ||
import io.kestra.jdbc.AbstractJdbcRepository; | ||
import io.kestra.jdbc.repository.AbstractRepository; | ||
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 AbstractExecutionDelayStorage extends AbstractRepository { | ||
protected AbstractJdbcRepository<ExecutionDelay> jdbcRepository; | ||
|
||
public AbstractExecutionDelayStorage(AbstractJdbcRepository<ExecutionDelay> jdbcRepository) { | ||
this.jdbcRepository = jdbcRepository; | ||
} | ||
|
||
public void get(Consumer<ExecutionDelay> consumer) { | ||
ZonedDateTime now = ZonedDateTime.now(); | ||
|
||
this.jdbcRepository | ||
.getDslContext() | ||
.transaction(configuration -> { | ||
SelectConditionStep<Record1<Object>> select = DSL | ||
.using(configuration) | ||
.select(DSL.field("value")) | ||
.from(this.jdbcRepository.getTable()) | ||
.where( | ||
DSL.field("date").lessOrEqual(now.toOffsetDateTime()) | ||
); | ||
|
||
this.jdbcRepository.fetch(select) | ||
.forEach(executionDelay -> { | ||
consumer.accept(executionDelay); | ||
jdbcRepository.delete(executionDelay); | ||
}); | ||
}); | ||
} | ||
|
||
public void save(ExecutionDelay executionDelay) { | ||
Map<Field<Object>, Object> fields = this.jdbcRepository.persistFields(executionDelay); | ||
this.jdbcRepository.persist(executionDelay, fields); | ||
} | ||
} |
Oops, something went wrong.