-
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): adapt scheduler for jdbc
- Loading branch information
1 parent
2e90c56
commit c3465ff
Showing
13 changed files
with
171 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.kestra.core.schedulers; | ||
|
||
import jakarta.inject.Singleton; | ||
|
||
@Singleton | ||
public interface Scheduler extends Runnable, AutoCloseable { | ||
|
||
} |
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
17 changes: 17 additions & 0 deletions
17
jdbc-mysql/src/test/java/io/kestra/schedulers/mysql/MysqlSchedulerScheduleTest.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,17 @@ | ||
package io.kestra.schedulers.mysql; | ||
|
||
import io.kestra.core.runners.FlowListeners; | ||
import io.kestra.core.schedulers.AbstractScheduler; | ||
import io.kestra.core.schedulers.SchedulerExecutionStateInterface; | ||
import io.kestra.core.schedulers.SchedulerScheduleTest; | ||
import io.kestra.jdbc.runner.JdbcScheduler; | ||
|
||
class MysqlSchedulerScheduleTest extends SchedulerScheduleTest { | ||
@Override | ||
protected AbstractScheduler scheduler(FlowListeners flowListenersServiceSpy, SchedulerExecutionStateInterface executionStateSpy) { | ||
return new JdbcScheduler( | ||
applicationContext, | ||
flowListenersServiceSpy | ||
); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
jdbc-postgres/src/test/java/io/kestra/schedulers/postgres/PostgresSchedulerScheduleTest.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,17 @@ | ||
package io.kestra.schedulers.postgres; | ||
|
||
import io.kestra.core.runners.FlowListeners; | ||
import io.kestra.core.schedulers.AbstractScheduler; | ||
import io.kestra.core.schedulers.SchedulerExecutionStateInterface; | ||
import io.kestra.core.schedulers.SchedulerScheduleTest; | ||
import io.kestra.jdbc.runner.JdbcScheduler; | ||
|
||
class PostgresSchedulerScheduleTest extends SchedulerScheduleTest { | ||
@Override | ||
protected AbstractScheduler scheduler(FlowListeners flowListenersServiceSpy, SchedulerExecutionStateInterface executionStateSpy) { | ||
return new JdbcScheduler( | ||
applicationContext, | ||
flowListenersServiceSpy | ||
); | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
jdbc/src/main/java/io/kestra/jdbc/runner/JdbcScheduler.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,57 @@ | ||
package io.kestra.jdbc.runner; | ||
|
||
import io.kestra.core.models.executions.Execution; | ||
import io.kestra.core.queues.QueueFactoryInterface; | ||
import io.kestra.core.queues.QueueInterface; | ||
import io.kestra.core.repositories.TriggerRepositoryInterface; | ||
import io.kestra.core.schedulers.*; | ||
import io.kestra.core.services.FlowListenersInterface; | ||
import io.micronaut.context.ApplicationContext; | ||
import io.micronaut.context.annotation.Replaces; | ||
import io.micronaut.inject.qualifiers.Qualifiers; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@JdbcRunnerEnabled | ||
@Singleton | ||
@Slf4j | ||
@Replaces(DefaultScheduler.class) | ||
public class JdbcScheduler extends AbstractScheduler { | ||
private final QueueInterface<Execution> executionQueue; | ||
private final TriggerRepositoryInterface triggerRepository; | ||
|
||
@SuppressWarnings("unchecked") | ||
@Inject | ||
public JdbcScheduler( | ||
ApplicationContext applicationContext, | ||
FlowListenersInterface flowListeners | ||
) { | ||
super(applicationContext, flowListeners); | ||
|
||
executionQueue = applicationContext.getBean(QueueInterface.class, Qualifiers.byName(QueueFactoryInterface.EXECUTION_NAMED)); | ||
triggerRepository = applicationContext.getBean(TriggerRepositoryInterface.class); | ||
triggerState = applicationContext.getBean(SchedulerTriggerStateInterface.class); | ||
executionState = applicationContext.getBean(SchedulerExecutionState.class); | ||
|
||
this.isReady = true; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
flowListeners.run(); | ||
|
||
// reset scheduler trigger at end | ||
executionQueue.receive( | ||
Scheduler.class, | ||
execution -> { | ||
if (execution.getState().getCurrent().isTerninated() && execution.getTrigger() != null) { | ||
triggerRepository | ||
.findByExecution(execution) | ||
.ifPresent(trigger -> triggerRepository.save(trigger.resetExecution())); | ||
} | ||
}); | ||
|
||
super.run(); | ||
} | ||
} |
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