-
Notifications
You must be signed in to change notification settings - Fork 10
Add cancelOn configuration #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...ot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/CancelOnEventFunction.java
This file contains hidden or 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,30 @@ | ||
| package com.inngest.springbootdemo.testfunctions; | ||
|
|
||
| import com.inngest.FunctionContext; | ||
| import com.inngest.InngestFunction; | ||
| import com.inngest.InngestFunctionConfigBuilder; | ||
| import com.inngest.Step; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| public class CancelOnEventFunction extends InngestFunction { | ||
|
|
||
| @NotNull | ||
| @Override | ||
| public InngestFunctionConfigBuilder config(InngestFunctionConfigBuilder builder) { | ||
| return builder | ||
| .id("cancelable-fn") | ||
| .name("Cancelable Function") | ||
| .cancelOn("cancel/cancelable") | ||
| .triggerEvent("test/cancelable"); | ||
| } | ||
|
|
||
| @Override | ||
| public String execute(FunctionContext ctx, Step step) { | ||
| step.waitForEvent("wait-forever", | ||
| "test/waiting-for-godot", | ||
| "10m", | ||
| null); | ||
|
|
||
| return "I didn't get canceled"; | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
...ot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/CancelOnMatchFunction.java
This file contains hidden or 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,31 @@ | ||
| package com.inngest.springbootdemo.testfunctions; | ||
|
|
||
| import com.inngest.FunctionContext; | ||
| import com.inngest.InngestFunction; | ||
| import com.inngest.InngestFunctionConfigBuilder; | ||
| import com.inngest.Step; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
|
|
||
| public class CancelOnMatchFunction extends InngestFunction { | ||
|
|
||
| @NotNull | ||
| @Override | ||
| public InngestFunctionConfigBuilder config(InngestFunctionConfigBuilder builder) { | ||
| return builder | ||
| .id("cancel-on-match-fn") | ||
| .name("Cancel On Match Function") | ||
| .cancelOn("cancel/cancel-on-match", "event.data.userId == async.data.userId") | ||
| .triggerEvent("test/cancel-on-match"); | ||
| } | ||
|
|
||
| @Override | ||
| public String execute(FunctionContext ctx, Step step) { | ||
| step.waitForEvent("wait-forever", | ||
| "test/waiting-for-godot", | ||
| "10m", | ||
| null); | ||
|
|
||
| return "I didn't get canceled"; | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
...pring-boot-demo/src/test/java/com/inngest/springbootdemo/CancellationIntegrationTest.java
This file contains hidden or 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,46 @@ | ||
| package com.inngest.springbootdemo; | ||
|
|
||
| import com.inngest.Inngest; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.parallel.Execution; | ||
| import org.junit.jupiter.api.parallel.ExecutionMode; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
|
|
||
| import java.util.Collections; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| @IntegrationTest | ||
| @Execution(ExecutionMode.CONCURRENT) | ||
| class CancellationIntegrationTest { | ||
| @Autowired | ||
| private DevServerComponent devServer; | ||
|
|
||
| @Autowired | ||
| private Inngest client; | ||
|
|
||
| @Test | ||
| void testCancelOnEventOnly() throws Exception { | ||
| String event = InngestFunctionTestHelpers.sendEvent(client, "test/cancelable").getIds()[0]; | ||
| Thread.sleep(1000); | ||
| InngestFunctionTestHelpers.sendEvent(client, "cancel/cancelable"); | ||
| Thread.sleep(1000); | ||
|
|
||
| RunEntry<Object> run = devServer.runsByEvent(event).first(); | ||
|
|
||
| assertEquals("Cancelled", run.getStatus()); | ||
| } | ||
|
|
||
| @Test | ||
| void testCancelOnIf() throws Exception { | ||
| String user23Event = InngestFunctionTestHelpers.sendEvent(client, "test/cancel-on-match", Collections.singletonMap("userId", "23")).getIds()[0]; | ||
| String user42Event = InngestFunctionTestHelpers.sendEvent(client, "test/cancel-on-match", Collections.singletonMap("userId", "42")).getIds()[0]; | ||
| Thread.sleep(1000); | ||
| InngestFunctionTestHelpers.sendEvent(client, "cancel/cancel-on-match", Collections.singletonMap("userId", "42")); | ||
| Thread.sleep(1000); | ||
|
|
||
| // Only the event matching the if expression is canceled | ||
| assertEquals("Running", devServer.runsByEvent(user23Event).first().getStatus()); | ||
| assertEquals("Cancelled", devServer.runsByEvent(user42Event).first().getStatus()); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The klaxon serializer for this adds inner quotes to the value
inngest-kt/inngest/src/main/kotlin/com/inngest/InngestFunctionConfigBuilder.kt
Line 263 in bf5da4f