-
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.
Per https://github.com/inngest/inngest/blob/main/docs/SDK_SPEC.md#512-ids-and-hashing, add `:n` starting with `:1` for repeated instances of a step id Mostly similar to inngest-js implementation https://github.com/inngest/inngest-js/blob/79069e1a3d700624ce49b323922c113fc952bcc6/packages/inngest/src/components/execution/v1.ts#L819-L831 The inngest-js SDK currently optionally warns of parallel indexing, but this isn't in scope for beta so I left it out
- Loading branch information
1 parent
593f8db
commit 10f39be
Showing
4 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/LoopFunction.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,32 @@ | ||
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 LoopFunction extends InngestFunction { | ||
|
||
@NotNull | ||
@Override | ||
public InngestFunctionConfigBuilder config(InngestFunctionConfigBuilder builder) { | ||
return builder | ||
.id("loop-fn") | ||
.name("Loop Function") | ||
.triggerEvent("test/loop"); | ||
} | ||
|
||
|
||
@Override | ||
public Integer execute(FunctionContext ctx, Step step) { | ||
int runningCount = 10; | ||
for (int i = 0; i < 5; i++) { | ||
int effectivelyFinalVariableForLambda = runningCount; | ||
runningCount = step.run("add-ten", () -> effectivelyFinalVariableForLambda + 10, Integer.class); | ||
} | ||
|
||
return runningCount; | ||
} | ||
} | ||
|
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
30 changes: 30 additions & 0 deletions
30
...pring-boot-demo/src/test/java/com/inngest/springbootdemo/LoopFunctionIntegrationTest.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; | ||
|
||
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 static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@IntegrationTest | ||
@Execution(ExecutionMode.CONCURRENT) | ||
class LoopFunctionIntegrationTest { | ||
@Autowired | ||
private DevServerComponent devServer; | ||
|
||
@Autowired | ||
private Inngest client; | ||
|
||
@Test | ||
void testStepsInLoopExecuteCorrectly() throws Exception { | ||
String loopEvent = InngestFunctionTestHelpers.sendEvent(client, "test/loop").first(); | ||
Thread.sleep(2000); | ||
|
||
RunEntry<Object> loopRun = devServer.runsByEvent(loopEvent).first(); | ||
assertEquals("Completed", loopRun.getStatus()); | ||
|
||
assertEquals(60, loopRun.getOutput()); | ||
} | ||
} |
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