-
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): cleanup queue and executor state
- Loading branch information
1 parent
4122422
commit 90372ac
Showing
7 changed files
with
86 additions
and
5 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.kestra.jdbc.runner; | ||
|
||
import io.kestra.core.queues.QueueException; | ||
import io.kestra.jdbc.DSLContextWrapper; | ||
import io.kestra.jdbc.JdbcConfiguration; | ||
import io.micronaut.context.ApplicationContext; | ||
import io.micronaut.context.annotation.ConfigurationProperties; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.scheduling.annotation.Scheduled; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
import lombok.Getter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.jooq.Record; | ||
import org.jooq.Table; | ||
import org.jooq.impl.DSL; | ||
|
||
import java.time.Duration; | ||
import java.time.ZonedDateTime; | ||
|
||
@Singleton | ||
@JdbcRunnerEnabled | ||
@Slf4j | ||
@Requires(property = "kestra.jdbc.cleaner") | ||
public class JdbcCleaner { | ||
private final DSLContextWrapper dslContextWrapper; | ||
private final Configuration configuration; | ||
|
||
protected final Table<Record> queueTable; | ||
|
||
@Inject | ||
public JdbcCleaner(ApplicationContext applicationContext) { | ||
JdbcConfiguration jdbcConfiguration = applicationContext.getBean(JdbcConfiguration.class); | ||
|
||
this.dslContextWrapper = applicationContext.getBean(DSLContextWrapper.class); | ||
this.configuration = applicationContext.getBean(Configuration.class); | ||
|
||
this.queueTable = DSL.table(jdbcConfiguration.tableConfig("queues").getTable()); | ||
} | ||
|
||
public void deleteQueue() throws QueueException { | ||
dslContextWrapper.transaction(configuration -> { | ||
int deleted = DSL | ||
.using(configuration) | ||
.delete(this.queueTable) | ||
.where( | ||
DSL.field("updated") | ||
.lessOrEqual(ZonedDateTime.now().minus(this.configuration.getRetention()).toOffsetDateTime()) | ||
) | ||
.execute(); | ||
log.info("Cleaned {} records from {}", deleted, this.queueTable.getName()); | ||
}); | ||
} | ||
|
||
@Scheduled(initialDelay = "${kestra.jdbc.cleaner.initial-delay}", fixedDelay = "${kestra.jdbc.cleaner.fixed-delay}") | ||
public void report() { | ||
deleteQueue(); | ||
} | ||
|
||
@ConfigurationProperties("kestra.jdbc.cleaner") | ||
@Getter | ||
public static class Configuration { | ||
Duration retention; | ||
} | ||
} |
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