-
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): implementation of WorkerTaskExecutionStorage
- Loading branch information
1 parent
521ddde
commit d308d51
Showing
13 changed files
with
184 additions
and
6 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
15 changes: 15 additions & 0 deletions
15
jdbc-mysql/src/main/java/io/kestra/runner/mysql/MysqlWorkerTaskExecutionStorage.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.WorkerTaskExecution; | ||
import io.kestra.jdbc.runner.AbstractWorkerTaskExecutionStorage; | ||
import io.kestra.repository.mysql.MysqlRepository; | ||
import io.micronaut.context.ApplicationContext; | ||
import jakarta.inject.Singleton; | ||
|
||
@Singleton | ||
@MysqlQueueEnabled | ||
public class MysqlWorkerTaskExecutionStorage extends AbstractWorkerTaskExecutionStorage { | ||
public MysqlWorkerTaskExecutionStorage(ApplicationContext applicationContext) { | ||
super(new MysqlRepository<>(WorkerTaskExecution.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
9 changes: 9 additions & 0 deletions
9
jdbc-mysql/src/test/java/io/kestra/runner/mysql/MysqlWorkerTaskExecutionStorageTest.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,9 @@ | ||
package io.kestra.runner.mysql; | ||
|
||
import io.kestra.core.models.triggers.multipleflows.AbstractMultipleConditionStorageTest; | ||
import io.kestra.jdbc.runner.AbstractWorkerTaskExecutionStorage; | ||
import io.kestra.jdbc.runner.AbstractWorkerTaskExecutionTest; | ||
|
||
class MysqlWorkerTaskExecutionStorageTest extends AbstractWorkerTaskExecutionTest { | ||
|
||
} |
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
...-postgres/src/main/java/io/kestra/runner/postgres/PostgresWorkerTaskExecutionStorage.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.WorkerTaskExecution; | ||
import io.kestra.jdbc.runner.AbstractWorkerTaskExecutionStorage; | ||
import io.kestra.repository.postgres.PostgresRepository; | ||
import io.micronaut.context.ApplicationContext; | ||
import jakarta.inject.Singleton; | ||
|
||
@Singleton | ||
@PostgresQueueEnabled | ||
public class PostgresWorkerTaskExecutionStorage extends AbstractWorkerTaskExecutionStorage { | ||
public PostgresWorkerTaskExecutionStorage(ApplicationContext applicationContext) { | ||
super(new PostgresRepository<>(WorkerTaskExecution.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
7 changes: 7 additions & 0 deletions
7
...tgres/src/test/java/io/kestra/runner/postgres/PostgresWorkerTaskExecutionStorageTest.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,7 @@ | ||
package io.kestra.runner.postgres; | ||
|
||
import io.kestra.jdbc.runner.AbstractWorkerTaskExecutionTest; | ||
|
||
class PostgresWorkerTaskExecutionStorageTest extends AbstractWorkerTaskExecutionTest { | ||
|
||
} |
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
55 changes: 55 additions & 0 deletions
55
jdbc/src/main/java/io/kestra/jdbc/runner/AbstractWorkerTaskExecutionStorage.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,55 @@ | ||
package io.kestra.jdbc.runner; | ||
|
||
import io.kestra.core.runners.WorkerTaskExecution; | ||
import io.kestra.jdbc.AbstractJdbcRepository; | ||
import io.kestra.jdbc.repository.AbstractRepository; | ||
import org.jooq.DSLContext; | ||
import org.jooq.Field; | ||
import org.jooq.Record1; | ||
import org.jooq.SelectConditionStep; | ||
import org.jooq.impl.DSL; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public abstract class AbstractWorkerTaskExecutionStorage extends AbstractRepository { | ||
protected AbstractJdbcRepository<WorkerTaskExecution> jdbcRepository; | ||
|
||
public AbstractWorkerTaskExecutionStorage(AbstractJdbcRepository<WorkerTaskExecution> jdbcRepository) { | ||
this.jdbcRepository = jdbcRepository; | ||
} | ||
|
||
public Optional<WorkerTaskExecution> get(String executionId) { | ||
return this.jdbcRepository | ||
.getDslContext() | ||
.transactionResult(configuration -> { | ||
SelectConditionStep<Record1<Object>> select = DSL | ||
.using(configuration) | ||
.select(DSL.field("value")) | ||
.from(this.jdbcRepository.getTable()) | ||
.where( | ||
DSL.field(DSL.quotedName("key")).eq(executionId) | ||
); | ||
|
||
return this.jdbcRepository.fetchOne(select); | ||
}); | ||
} | ||
|
||
public void save(List<WorkerTaskExecution> workerTaskExecutions) { | ||
this.jdbcRepository | ||
.getDslContext() | ||
.transaction(configuration -> { | ||
DSLContext context = DSL.using(configuration); | ||
|
||
workerTaskExecutions.forEach(workerTaskExecution -> { | ||
Map<Field<Object>, Object> fields = this.jdbcRepository.persistFields(workerTaskExecution); | ||
this.jdbcRepository.persist(workerTaskExecution, context, fields); | ||
}); | ||
}); | ||
} | ||
|
||
public void delete(WorkerTaskExecution workerTaskExecution) { | ||
this.jdbcRepository.delete(workerTaskExecution); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
jdbc/src/test/java/io/kestra/jdbc/runner/AbstractWorkerTaskExecutionTest.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,56 @@ | ||
package io.kestra.jdbc.runner; | ||
|
||
import io.kestra.core.models.executions.Execution; | ||
import io.kestra.core.models.executions.TaskRun; | ||
import io.kestra.core.tasks.flows.Flow; | ||
import io.kestra.core.runners.WorkerTaskExecution; | ||
import io.kestra.core.utils.IdUtils; | ||
import io.kestra.jdbc.JdbcTestUtils; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@MicronautTest(transactional = false) | ||
public abstract class AbstractWorkerTaskExecutionTest { | ||
@Inject | ||
AbstractWorkerTaskExecutionStorage workerTaskExecutionStorage; | ||
|
||
@Inject | ||
JdbcTestUtils jdbcTestUtils; | ||
|
||
@Test | ||
void suite() throws Exception { | ||
|
||
WorkerTaskExecution workerTaskExecution = WorkerTaskExecution.builder() | ||
.execution(Execution.builder().id(IdUtils.create()).build()) | ||
.task(Flow.builder().type(Flow.class.getName()).id(IdUtils.create()).build()) | ||
.taskRun(TaskRun.builder().id(IdUtils.create()).build()) | ||
.build(); | ||
|
||
workerTaskExecutionStorage.save(List.of(workerTaskExecution)); | ||
|
||
|
||
Optional<WorkerTaskExecution> find = workerTaskExecutionStorage.get(workerTaskExecution.getExecution().getId()); | ||
assertThat(find.isPresent(), is(true)); | ||
assertThat(find.get().getExecution().getId(), is(workerTaskExecution.getExecution().getId())); | ||
|
||
|
||
workerTaskExecutionStorage.delete(workerTaskExecution); | ||
|
||
find = workerTaskExecutionStorage.get(workerTaskExecution.getExecution().getId()); | ||
assertThat(find.isPresent(), is(false)); | ||
} | ||
|
||
@BeforeEach | ||
protected void init() { | ||
jdbcTestUtils.drop(); | ||
jdbcTestUtils.migrate(); | ||
} | ||
} |