diff --git a/README.md b/README.md
index 6e990b00..2ea745c7 100644
--- a/README.md
+++ b/README.md
@@ -8,32 +8,37 @@
Kotlin
```kotlin
-import com.inngest.InngestFunction
-import com.inngest.FunctionOptions
-import com.inngest.FunctionTrigger
-
-val myFunction = InngestFunction(
- FunctionOptions(
- id = "fn-id-slug",
- name = "My function!",
- triggers = arrayOf(FunctionTrigger(event = "user.signup")),
- ),
-) { ctx, step ->
- val x = 10
-
- val res =
- step.run("add-ten") { ->
- x + 10
- }
- val add: Int =
- step.run("multiply-by-100") {
- res * 100
- }
- step.sleep("wait-one-minute", Duration.ofSeconds(60))
-
- step.run("last-step") { res * add }
-
- hashMapOf("message" to "success")
+class TranscodeVideo : InngestFunction() {
+ override fun config(builder: InngestFunctionConfigBuilder): InngestFunctionConfigBuilder =
+ builder
+ .id("process-video")
+ .name("Process video upload")
+ .triggerEvent("media/video.uploaded")
+ .concurrency(10)
+
+ override fun execute(
+ ctx: FunctionContext,
+ step: Step,
+ ): HashMap {
+ val transcription =
+ step.run("transcribe-video") {
+ // Download video, run through transcription model, return output
+ "Hi there, My name is Jamie..." // dummy example content
+ }
+
+ val summary =
+ step.run("summarize") {
+ // Send t
+ "Hi there, My name is Jamie..." // dummy example content
+ }
+
+ step.run("save-results") {
+ // Save summary, to your database
+ // database.save(event.data["videoId"], transcription, summary)
+ }
+
+ return hashMapOf("restored" to false)
+ }
}
```
@@ -43,9 +48,28 @@ val myFunction = InngestFunction(
Java (Coming soon)
-## Declaring dependencies
+## Defining configuration
-WIP
+Define your function's configuration using the `config` method and the `InngestFunctionConfigBuilder` class.
+The `config` method must be overridden and an `id` is required. All options should are discoverable via
+the builder class passed as the only argument to the `config` method.
+
+
+ Kotlin
+
+```kotlin
+class TranscodeVideo : InngestFunction() {
+ override fun config(builder: InngestFunctionConfigBuilder): InngestFunctionConfigBuilder =
+ builder
+ .id("process-video")
+ .name("Process video upload")
+ .triggerEvent("media/video.uploaded")
+ .concurrency(10)
+
+}
+```
+
+
## Contributing [WIP]
@@ -57,7 +81,6 @@ make dev-ktor
This runs a `ktor` web server to test the SDK against the dev server.
-
To run the `spring-boot` test server:
```
diff --git a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/FollowupFunction.java b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/FollowupFunction.java
index 7d881957..df3f0823 100644
--- a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/FollowupFunction.java
+++ b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/FollowupFunction.java
@@ -5,13 +5,18 @@
import java.util.LinkedHashMap;
-@FunctionConfig(
- id = "fn-follow-up",
- name = "My follow up function!"
-)
-@FunctionEventTrigger(event = "user.signup.completed")
-@FunctionEventTrigger(event = "random-event")
public class FollowupFunction extends InngestFunction {
+
+ @NotNull
+ @Override
+ public InngestFunctionConfigBuilder config(InngestFunctionConfigBuilder builder) {
+ return builder
+ .id("fn-follow-up")
+ .name("My follow up function!")
+ .triggerEvent("user.signup.completed")
+ .triggerEvent("random-event");
+ }
+
@Override
public LinkedHashMap execute(@NotNull FunctionContext ctx, @NotNull Step step) {
System.out.println("-> follow up handler called " + ctx.getEvent().getName());
diff --git a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/UserSignupFunction.java b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/UserSignupFunction.java
index b4819504..ef516fca 100644
--- a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/UserSignupFunction.java
+++ b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/UserSignupFunction.java
@@ -6,9 +6,17 @@
import java.time.Duration;
import java.util.HashMap;
-@FunctionConfig(id = "fn-id-slug", name = "My function!")
-@FunctionEventTrigger(event = "user-signup")
public class UserSignupFunction extends InngestFunction {
+
+ @NotNull
+ @Override
+ public InngestFunctionConfigBuilder config(InngestFunctionConfigBuilder builder) {
+ return builder
+ .id("fn-id-slug")
+ .name("My Function!")
+ .triggerEvent("user-signup");
+ }
+
@Override
public HashMap execute(@NotNull FunctionContext ctx, @NotNull Step step) {
int x = 10;
diff --git a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/CustomStepFunction.java b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/CustomStepFunction.java
index b0ba7dac..aaea1ab1 100644
--- a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/CustomStepFunction.java
+++ b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/CustomStepFunction.java
@@ -1,11 +1,19 @@
package com.inngest.springbootdemo.testfunctions;
import com.inngest.*;
+import org.jetbrains.annotations.NotNull;
-@FunctionConfig(id = "custom-result-fn", name = "Custom Result Function")
-@FunctionEventTrigger(event = "test/custom.result.step")
public class CustomStepFunction extends InngestFunction {
+ @NotNull
+ @Override
+ public InngestFunctionConfigBuilder config(InngestFunctionConfigBuilder builder) {
+ return builder
+ .id("custom-result-fn")
+ .name("Custom Result Function")
+ .triggerEvent("test/custom.result.step");
+ }
+
private final int count = 0;
@Override
diff --git a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/EmptyStepFunction.java b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/EmptyStepFunction.java
index 807fba34..abc638ef 100644
--- a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/EmptyStepFunction.java
+++ b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/EmptyStepFunction.java
@@ -1,10 +1,19 @@
package com.inngest.springbootdemo.testfunctions;
import com.inngest.*;
+import org.jetbrains.annotations.NotNull;
-@FunctionConfig(id = "no-step-fn", name = "No Step Function")
-@FunctionEventTrigger(event = "test/no-step")
public class EmptyStepFunction extends InngestFunction {
+
+ @NotNull
+ @Override
+ public InngestFunctionConfigBuilder config(InngestFunctionConfigBuilder builder) {
+ return builder
+ .id("no-step-fn")
+ .name("No Step Function")
+ .triggerEvent("test/no-step");
+ }
+
@Override
public String execute(FunctionContext ctx, Step step) {
return "hello world";
diff --git a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/NonRetriableErrorFunction.java b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/NonRetriableErrorFunction.java
index 431435a1..b6f9527a 100644
--- a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/NonRetriableErrorFunction.java
+++ b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/NonRetriableErrorFunction.java
@@ -1,11 +1,19 @@
package com.inngest.springbootdemo.testfunctions;
import com.inngest.*;
+import org.jetbrains.annotations.NotNull;
-@FunctionConfig(id = "non-retriable-fn", name = "NonRetriable Function")
-@FunctionEventTrigger(event = "test/non.retriable")
public class NonRetriableErrorFunction extends InngestFunction {
+ @NotNull
+ @Override
+ public InngestFunctionConfigBuilder config(InngestFunctionConfigBuilder builder) {
+ return builder
+ .id("non-retriable-fn")
+ .name("NonRetriable Function")
+ .triggerEvent("test/non.retriable");
+ }
+
@Override
public String execute(FunctionContext ctx, Step step) {
step.run("fail-step", () -> {
diff --git a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/RetriableErrorFunction.java b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/RetriableErrorFunction.java
index 3c5aa82f..8a6f06a2 100644
--- a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/RetriableErrorFunction.java
+++ b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/RetriableErrorFunction.java
@@ -1,10 +1,19 @@
package com.inngest.springbootdemo.testfunctions;
import com.inngest.*;
+import org.jetbrains.annotations.NotNull;
-@FunctionConfig(id = "retriable-fn", name = "Retriable Function")
-@FunctionEventTrigger(event = "test/retriable")
public class RetriableErrorFunction extends InngestFunction {
+
+ @NotNull
+ @Override
+ public InngestFunctionConfigBuilder config(InngestFunctionConfigBuilder builder) {
+ return builder
+ .id("retriable-fn")
+ .name("Retriable Function")
+ .triggerEvent("test/retriable");
+ }
+
static int retryCount = 0;
@Override
diff --git a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/SendEventFunction.java b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/SendEventFunction.java
index 3d9a166e..09a9d673 100644
--- a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/SendEventFunction.java
+++ b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/SendEventFunction.java
@@ -1,13 +1,21 @@
package com.inngest.springbootdemo.testfunctions;
import com.inngest.*;
+import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
-@FunctionConfig(id = "send-fn", name = "Send Function")
-@FunctionEventTrigger(event = "test/send")
public class SendEventFunction extends InngestFunction {
+ @NotNull
+ @Override
+ public InngestFunctionConfigBuilder config(InngestFunctionConfigBuilder builder) {
+ return builder
+ .id("send-fn")
+ .name("Send Function")
+ .triggerEvent("test/send");
+ }
+
@Override
public SendEventsResponse execute(FunctionContext ctx, Step step) {
return step.sendEvent("send-test", new InngestEvent(
diff --git a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/SleepStepFunction.java b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/SleepStepFunction.java
index 3353344d..5dfdba5b 100644
--- a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/SleepStepFunction.java
+++ b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/SleepStepFunction.java
@@ -1,12 +1,21 @@
package com.inngest.springbootdemo.testfunctions;
import com.inngest.*;
+import org.jetbrains.annotations.NotNull;
import java.time.Duration;
-@FunctionConfig(id = "sleep-fn", name = "Sleep Function")
-@FunctionEventTrigger(event = "test/sleep")
public class SleepStepFunction extends InngestFunction {
+
+ @NotNull
+ @Override
+ public InngestFunctionConfigBuilder config(InngestFunctionConfigBuilder builder) {
+ return builder
+ .id("sleep-fn")
+ .name("Sleep Function")
+ .triggerEvent("test/sleep");
+ }
+
@Override
public Integer execute(FunctionContext ctx, Step step) {
int result = step.run("num", () -> 42, Integer.class);
diff --git a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/TwoStepsFunction.java b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/TwoStepsFunction.java
index 985cc2a8..eb018bd6 100644
--- a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/TwoStepsFunction.java
+++ b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/TwoStepsFunction.java
@@ -1,11 +1,20 @@
package com.inngest.springbootdemo.testfunctions;
import com.inngest.*;
+import org.jetbrains.annotations.NotNull;
-@FunctionConfig(id = "two-steps-fn", name = "Two Steps Function")
-@FunctionEventTrigger(event = "test/two.steps")
public class TwoStepsFunction extends InngestFunction {
+ @NotNull
+ @Override
+ public InngestFunctionConfigBuilder config(InngestFunctionConfigBuilder builder) {
+ return builder
+ .id("two-steps-fn")
+ .name("Two Steps Function")
+ .triggerEvent("test/two.steps");
+ }
+
+
private final int count = 0;
@Override
diff --git a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/WaitForEventFunction.java b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/WaitForEventFunction.java
index 5ddb89b5..725bfab2 100644
--- a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/WaitForEventFunction.java
+++ b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/WaitForEventFunction.java
@@ -1,11 +1,19 @@
package com.inngest.springbootdemo.testfunctions;
import com.inngest.*;
+import org.jetbrains.annotations.NotNull;
-@FunctionConfig(id = "wait-for-event-fn", name = "Wait for Event Function")
-@FunctionEventTrigger(event = "test/wait-for-event")
public class WaitForEventFunction extends InngestFunction {
+ @NotNull
+ @Override
+ public InngestFunctionConfigBuilder config(InngestFunctionConfigBuilder builder) {
+ return builder
+ .id("wait-for-event-fn")
+ .name("Wait for Event Function")
+ .triggerEvent("test/wait-for-event");
+ }
+
@Override
public String execute(FunctionContext ctx, Step step) {
Object event = step.waitForEvent("wait-test",
diff --git a/inngest-test-server/src/main/kotlin/com/inngest/testserver/App.kt b/inngest-test-server/src/main/kotlin/com/inngest/testserver/App.kt
index ba8983ec..f378e066 100644
--- a/inngest-test-server/src/main/kotlin/com/inngest/testserver/App.kt
+++ b/inngest-test-server/src/main/kotlin/com/inngest/testserver/App.kt
@@ -15,20 +15,26 @@ data class Result(
const val FOLLOW_UP_EVENT_NAME = "user.signup.completed"
-data class IngestData(val message: String)
-
fun Application.module() {
val inngest = Inngest(appId = "ktor-dev")
routing {
- serve("/api/inngest", inngest, listOf(ProcessAlbum(), RestoreFromGlacier()))
+ serve(
+ "/api/inngest", inngest,
+ listOf(
+ ProcessAlbum(),
+ RestoreFromGlacier(),
+ ProcessUserSignup(),
+ TranscodeVideo(),
+ ),
+ )
}
}
fun main() {
- var port = 8080
+ val port = 8080
- println("Test server running on port " + port)
+ println("Test server running on port $port")
embeddedServer(
Netty,
diff --git a/inngest-test-server/src/main/kotlin/com/inngest/testserver/FollowupFunction.kt b/inngest-test-server/src/main/kotlin/com/inngest/testserver/FollowupFunction.kt
deleted file mode 100644
index b7e49ae3..00000000
--- a/inngest-test-server/src/main/kotlin/com/inngest/testserver/FollowupFunction.kt
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.inngest.testserver
-
-import com.inngest.*
-
-@FunctionConfig(id = "fn-follow-up", name = "My follow up function!")
-@FunctionEventTrigger(event = "user.signup.completed")
-@FunctionEventTrigger(event = "random-event")
-class FollowupFunction : InngestFunction() {
- override fun execute(
- ctx: FunctionContext,
- step: Step,
- ): LinkedHashMap {
- println("-> follow up handler called " + ctx.event.name)
- return ctx.event.data
- }
-}
diff --git a/inngest-test-server/src/main/kotlin/com/inngest/testserver/ProcessAlbum.kt b/inngest-test-server/src/main/kotlin/com/inngest/testserver/ProcessAlbum.kt
index e19a508c..25274cf1 100644
--- a/inngest-test-server/src/main/kotlin/com/inngest/testserver/ProcessAlbum.kt
+++ b/inngest-test-server/src/main/kotlin/com/inngest/testserver/ProcessAlbum.kt
@@ -3,36 +3,39 @@ package com.inngest.testserver
import com.inngest.*
import java.time.Duration
-@FunctionConfig(id = "ProcessAlbum", name = "ProcessAlbum")
-@FunctionEventTrigger(event = "delivery/process.requested")
+/**
+ * A demo function that accepts an event in a batch and invokes a child function
+ */
class ProcessAlbum : InngestFunction() {
+ override fun config(builder: InngestFunctionConfigBuilder): InngestFunctionConfigBuilder =
+ builder
+ .id("ProcessAlbum")
+ .name("Process Album!")
+ .triggerEvent("delivery/process.requested")
+ .trigger(InngestFunctionTriggers.Cron("5 0 * 8 *"))
+ .batchEvents(30, Duration.ofSeconds(10))
+
override fun execute(
ctx: FunctionContext,
step: Step,
): LinkedHashMap {
+// val list = ctx.events.map { e -> e.data.get("something") }
+// println(list);
- // NOTE - App ID is set on the serve level
- val res = step.invoke