-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jdbc): handle trigger in jdbc heartbeat/resubmit (#2240)
This fix follow the JDBC heartbeat & task resubmit feature recently released in the 0.12
- Loading branch information
1 parent
ce6ad77
commit e045440
Showing
30 changed files
with
606 additions
and
34 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
19 changes: 19 additions & 0 deletions
19
core/src/main/java/io/kestra/core/queues/WorkerTriggerResultQueueInterface.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,19 @@ | ||
package io.kestra.core.queues; | ||
|
||
import io.kestra.core.exceptions.DeserializationException; | ||
import io.kestra.core.runners.WorkerTriggerResult; | ||
import io.kestra.core.utils.Either; | ||
|
||
import java.io.Closeable; | ||
import java.util.function.Consumer; | ||
|
||
/* | ||
* Required for the QueueFactory, to have common interface with JDBC & Kafka | ||
*/ | ||
public interface WorkerTriggerResultQueueInterface extends Closeable { | ||
Runnable receive(String consumerGroup, Class<?> queueType, Consumer<Either<WorkerTriggerResult, DeserializationException>> consumer); | ||
|
||
void pause(); | ||
|
||
void cleanup(); | ||
} |
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
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
49 changes: 49 additions & 0 deletions
49
core/src/test/java/io/kestra/core/tasks/test/SleepTrigger.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,49 @@ | ||
package io.kestra.core.tasks.test; | ||
|
||
import io.kestra.core.models.annotations.PluginProperty; | ||
import io.kestra.core.models.conditions.ConditionContext; | ||
import io.kestra.core.models.executions.Execution; | ||
import io.kestra.core.models.triggers.AbstractTrigger; | ||
import io.kestra.core.models.triggers.PollingTriggerInterface; | ||
import io.kestra.core.models.triggers.TriggerContext; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import java.time.Duration; | ||
import java.util.Optional; | ||
|
||
/** | ||
* This trigger is used in unit tests where we need a task that wait a little to be able to check the resubmit of triggers. | ||
*/ | ||
@SuperBuilder | ||
@ToString | ||
@EqualsAndHashCode | ||
@Getter | ||
@NoArgsConstructor | ||
public class SleepTrigger extends AbstractTrigger implements PollingTriggerInterface { | ||
|
||
@PluginProperty | ||
@NotNull | ||
private Long duration; | ||
|
||
@Override | ||
public Optional<Execution> evaluate(ConditionContext conditionContext, TriggerContext context) { | ||
// Try catch to avoid flakky test | ||
try { | ||
Thread.sleep(duration); | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Duration getInterval() { | ||
return null; | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
jdbc-h2/src/main/java/io/kestra/runner/h2/H2WorkerTriggerResultQueue.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,41 @@ | ||
package io.kestra.runner.h2; | ||
|
||
import io.kestra.core.exceptions.DeserializationException; | ||
import io.kestra.core.queues.WorkerTriggerResultQueueInterface; | ||
import io.kestra.core.runners.WorkerTriggerResult; | ||
import io.kestra.core.utils.Either; | ||
import io.kestra.jdbc.JdbcWorkerTriggerResultQueueService; | ||
import io.micronaut.context.ApplicationContext; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.function.Consumer; | ||
|
||
@Slf4j | ||
public class H2WorkerTriggerResultQueue extends H2Queue<WorkerTriggerResult> implements WorkerTriggerResultQueueInterface { | ||
private final JdbcWorkerTriggerResultQueueService jdbcWorkerTriggerResultQueueService; | ||
|
||
public H2WorkerTriggerResultQueue(ApplicationContext applicationContext) { | ||
super(WorkerTriggerResult.class, applicationContext); | ||
this.jdbcWorkerTriggerResultQueueService = applicationContext.getBean(JdbcWorkerTriggerResultQueueService.class); | ||
} | ||
|
||
@Override | ||
public Runnable receive(String consumerGroup, Class<?> queueType, Consumer<Either<WorkerTriggerResult, DeserializationException>> consumer) { | ||
return jdbcWorkerTriggerResultQueueService.receive(consumerGroup, queueType, consumer); | ||
} | ||
|
||
@Override | ||
public void pause() { | ||
jdbcWorkerTriggerResultQueueService.pause(); | ||
} | ||
|
||
@Override | ||
public void cleanup() { | ||
jdbcWorkerTriggerResultQueueService.cleanup(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
jdbcWorkerTriggerResultQueueService.close(); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
jdbc-h2/src/main/resources/migrations/h2/V1_3__worker_heartbeat.sql
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,2 @@ | ||
ALTER TABLE worker_job_running | ||
DROP COLUMN "taskrun_id"; |
7 changes: 7 additions & 0 deletions
7
jdbc-h2/src/test/java/io/kestra/runner/h2/H2HeartbeatTest.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.h2; | ||
|
||
import io.kestra.jdbc.runner.JdbcHeartbeatTest; | ||
|
||
class H2HeartbeatTest extends JdbcHeartbeatTest { | ||
|
||
} |
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
41 changes: 41 additions & 0 deletions
41
jdbc-mysql/src/main/java/io/kestra/runner/mysql/MysqlWorkerTriggerResultQueue.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,41 @@ | ||
package io.kestra.runner.mysql; | ||
|
||
import io.kestra.core.exceptions.DeserializationException; | ||
import io.kestra.core.queues.WorkerTriggerResultQueueInterface; | ||
import io.kestra.core.runners.WorkerTriggerResult; | ||
import io.kestra.core.utils.Either; | ||
import io.kestra.jdbc.JdbcWorkerTriggerResultQueueService; | ||
import io.micronaut.context.ApplicationContext; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.function.Consumer; | ||
|
||
@Slf4j | ||
public class MysqlWorkerTriggerResultQueue extends MysqlQueue<WorkerTriggerResult> implements WorkerTriggerResultQueueInterface { | ||
private final JdbcWorkerTriggerResultQueueService jdbcWorkerTriggerResultQueueService; | ||
|
||
public MysqlWorkerTriggerResultQueue(ApplicationContext applicationContext) { | ||
super(WorkerTriggerResult.class, applicationContext); | ||
this.jdbcWorkerTriggerResultQueueService = applicationContext.getBean(JdbcWorkerTriggerResultQueueService.class); | ||
} | ||
|
||
@Override | ||
public Runnable receive(String consumerGroup, Class<?> queueType, Consumer<Either<WorkerTriggerResult, DeserializationException>> consumer) { | ||
return jdbcWorkerTriggerResultQueueService.receive(consumerGroup, queueType, consumer); | ||
} | ||
|
||
@Override | ||
public void pause() { | ||
jdbcWorkerTriggerResultQueueService.pause(); | ||
} | ||
|
||
@Override | ||
public void cleanup() { | ||
jdbcWorkerTriggerResultQueueService.cleanup(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
jdbcWorkerTriggerResultQueueService.close(); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
jdbc-mysql/src/main/resources/migrations/mysql/V1_3__worker_heartbeat.sql
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,2 @@ | ||
ALTER TABLE worker_job_running | ||
DROP COLUMN taskrun_id; |
7 changes: 7 additions & 0 deletions
7
jdbc-mysql/src/test/java/io/kestra/runner/mysql/MysqlHeartbeatTest.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.mysql; | ||
|
||
import io.kestra.jdbc.runner.JdbcHeartbeatTest; | ||
|
||
class MysqlHeartbeatTest extends JdbcHeartbeatTest { | ||
|
||
} |
Oops, something went wrong.