-
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.
feat(core): allow to skip and execution (#1678)
close #767
- Loading branch information
1 parent
38f6048
commit 304d921
Showing
9 changed files
with
194 additions
and
0 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
19 changes: 19 additions & 0 deletions
19
core/src/main/java/io/kestra/core/services/SkipExecutionService.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.services; | ||
|
||
import jakarta.inject.Singleton; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@Singleton | ||
public class SkipExecutionService { | ||
private volatile List<String> skipExecutions = Collections.emptyList(); | ||
|
||
public synchronized void setSkipExecutions(List<String> skipExecutions) { | ||
this.skipExecutions = skipExecutions; | ||
} | ||
|
||
public boolean skipExecution(String executionId) { | ||
return skipExecutions.contains(executionId); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
core/src/test/java/io/kestra/core/runners/SkipExecutionCaseTest.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,67 @@ | ||
package io.kestra.core.runners; | ||
|
||
import io.kestra.core.models.executions.Execution; | ||
import io.kestra.core.models.flows.Flow; | ||
import io.kestra.core.models.flows.State; | ||
import io.kestra.core.queues.QueueFactoryInterface; | ||
import io.kestra.core.queues.QueueInterface; | ||
import io.kestra.core.repositories.ExecutionRepositoryInterface; | ||
import io.kestra.core.services.SkipExecutionService; | ||
import io.kestra.core.tasks.debugs.Return; | ||
import io.kestra.core.utils.IdUtils; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Named; | ||
import jakarta.inject.Singleton; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.TimeoutException; | ||
import java.util.function.Consumer; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
@Singleton | ||
public class SkipExecutionCaseTest { | ||
@Inject | ||
@Named(QueueFactoryInterface.EXECUTION_NAMED) | ||
protected QueueInterface<Execution> executionQueue; | ||
|
||
@Inject | ||
protected RunnerUtils runnerUtils; | ||
|
||
@Inject | ||
private ExecutionRepositoryInterface executionRepository; | ||
|
||
@Inject | ||
private SkipExecutionService skipExecutionService; | ||
|
||
public void skipExecution() throws TimeoutException, InterruptedException { | ||
Flow flow = createFlow(); | ||
Execution execution1 = runnerUtils.newExecution(flow, null, null); | ||
String execution1Id = execution1.getId(); | ||
skipExecutionService.setSkipExecutions(List.of(execution1Id)); | ||
|
||
executionQueue.emit(execution1); | ||
Execution execution2 = runnerUtils.runOne("io.kestra.tests", "minimal"); | ||
|
||
// the execution 2 should be in success and the 1 still created | ||
assertThat(execution2.getState().getCurrent(), is(State.Type.SUCCESS)); | ||
Thread.sleep(25); // to be 100% sure that it works, add a slight delay to be sure we didn't miss the execution by chance | ||
execution1 = executionRepository.findById(execution1Id).get(); | ||
assertThat(execution1.getState().getCurrent(), is(State.Type.CREATED)); | ||
} | ||
|
||
private Flow createFlow() { | ||
return Flow.builder() | ||
.id(IdUtils.create()) | ||
.namespace("io.kestra.unittest") | ||
.revision(1) | ||
.tasks(Collections.singletonList(Return.builder() | ||
.id("test") | ||
.type(Return.class.getName()) | ||
.format("{{ inputs.testInputs }}") | ||
.build())) | ||
.build(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
core/src/test/java/io/kestra/core/services/SkipExecutionServiceTest.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,27 @@ | ||
package io.kestra.core.services; | ||
|
||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
@MicronautTest | ||
class SkipExecutionServiceTest { | ||
@Inject | ||
private SkipExecutionService skipExecutionService; | ||
|
||
@Test | ||
void test() { | ||
var executionToSkip = "aaabbbccc"; | ||
var executionNotToSkip = "bbbcccddd"; | ||
|
||
skipExecutionService.setSkipExecutions(List.of(executionToSkip)); | ||
|
||
assertThat(skipExecutionService.skipExecution(executionToSkip), is(true)); | ||
assertThat(skipExecutionService.skipExecution(executionNotToSkip), is(false)); | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
runner-memory/src/test/java/io/kestra/runner/memory/MemorySkipExecutionTest.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,22 @@ | ||
package io.kestra.runner.memory; | ||
|
||
import io.kestra.core.runners.AbstractMemoryRunnerTest; | ||
import io.kestra.core.runners.SkipExecutionCaseTest; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.RepeatedTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
@MicronautTest | ||
class MemorySkipExecutionTest extends AbstractMemoryRunnerTest { | ||
@Inject | ||
private SkipExecutionCaseTest skipExecutionCaseTest; | ||
|
||
@Test | ||
void skipExecution() throws TimeoutException, InterruptedException { | ||
skipExecutionCaseTest.skipExecution(); | ||
} | ||
} |