-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- followed similar pattern to `InngestFunctionTriggers` but didn't reuse that class for a few reasons - `if` concept is similar but for triggers it gets serialized as `expression` but is `if` for cancel - `timeout` is only used by cancel and not for triggers and vice versa with `cron`, so it seems the `InngestFunctionTrigger` class's fields would be sparsely populated for all the concrete cases and not provide too much value in sharing code - While I like the idea of calling the "thing" that sets off Cancel as "CancelTrigger" or "CancellationTrigger", I thought this could be confusing since [triggers are their own key under configuration](https://github.com/inngest/inngest/blame/0ac11f2c312c066e517e53749052dd89fd2926ba/docs/SDK_SPEC.md#L478) - `Cancellation` name avoided "trigger" for reason above and followed pattern in https://github.com/inngest/inngest-js/blob/0e51903d5968a7287dd7e518bd5cc8acec3e6f3e/packages/inngest/src/types.ts#L901 - I originally was going to implement with `match` as well per https://www.inngest.com/docs/reference/typescript/functions/cancel-on, but I saw later that [it's currently deprecated so I stuck to `if` only](https://github.com/inngest/inngest-js/blob/0e51903d5968a7287dd7e518bd5cc8acec3e6f3e/packages/inngest/src/types.ts#L946). - Per the flexibility of timeout in https://github.com/inngest/inngest/blob/0ac11f2c312c066e517e53749052dd89fd2926ba/docs/SDK_SPEC.md?plain=1#L580-L583 The type for timeout is either `Duration` or `Instant`.
- Loading branch information
1 parent
37aabd7
commit ccddba0
Showing
8 changed files
with
207 additions
and
1 deletion.
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 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 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 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 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