-
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.
- Loading branch information
Showing
13 changed files
with
172 additions
and
105 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
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,34 @@ | ||
plugins { | ||
`java-library` | ||
id("io.spring.dependency-management") version "1.1.4" | ||
} | ||
|
||
group = "com.inngest" | ||
version = "0.0.1-SNAPSHOT" | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
api(project(":inngest-core")) | ||
|
||
implementation("org.springframework.boot:spring-boot-starter-web") | ||
testImplementation("org.springframework.boot:spring-boot-starter-test") | ||
} | ||
|
||
dependencyManagement { | ||
imports { | ||
mavenBom("org.springframework.boot:spring-boot-dependencies:2.7.18") { | ||
bomProperty("kotlin.version", "1.9.10") | ||
} | ||
} | ||
} | ||
|
||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
} |
22 changes: 22 additions & 0 deletions
22
inngest-spring-boot-adapter/src/main/java/com/inngest/springboot/InngestConfiguration.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 com.inngest.springboot; | ||
|
||
import com.inngest.CommHandler; | ||
import com.inngest.Inngest; | ||
import com.inngest.InngestFunction; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
import java.util.HashMap; | ||
|
||
public abstract class InngestConfiguration { | ||
protected abstract HashMap<String, InngestFunction> functions(); | ||
|
||
@Bean | ||
protected abstract Inngest inngestClient(); | ||
|
||
|
||
@Bean | ||
protected CommHandler commHandler(@Autowired Inngest inngestClient) { | ||
return new CommHandler(functions(), inngestClient); | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...va/com/inngest/springbootdemo/Result.java → ...n/java/com/inngest/springboot/Result.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
4 changes: 4 additions & 0 deletions
4
inngest-spring-boot-adapter/src/main/resources/application.yml
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,4 @@ | ||
server: | ||
port: 8080 # We probably want to change this to 8081 to avoid port conflicts | ||
# but I kept it for now because of the hardcoded URL that are sent | ||
# to the inngest dev-server. |
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
83 changes: 83 additions & 0 deletions
83
inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/DemoConfiguration.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,83 @@ | ||
package com.inngest.springbootdemo; | ||
|
||
|
||
import com.inngest.*; | ||
import com.inngest.springboot.InngestConfiguration; | ||
import com.inngest.springboot.Result; | ||
import kotlin.jvm.functions.Function2; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.time.Duration; | ||
import java.util.HashMap; | ||
|
||
@Configuration | ||
public class DemoConfiguration extends InngestConfiguration { | ||
|
||
@Override | ||
public HashMap<String, InngestFunction> functions() { | ||
String followUpEvent = "user.signup.completed"; | ||
FunctionTrigger fnTrigger = new FunctionTrigger("user-signup", null, null); | ||
FunctionTrigger[] triggers = {fnTrigger}; | ||
FunctionOptions fnConfig = new FunctionOptions("fn-id-slug", "My function!", triggers); | ||
|
||
Function2<FunctionContext, Step, HashMap<String, String>> handler = (ctx, step) -> { | ||
int x = 10; | ||
|
||
System.out.println("-> handler called " + ctx.getEvent().getName()); | ||
|
||
int y = step.run("add-ten", () -> x + 10, Integer.class); | ||
|
||
Result res = step.run("cast-to-type-add-ten", () -> { | ||
System.out.println("-> running step 1!! " + x); | ||
return new Result(y + 10); | ||
}, Result.class); | ||
|
||
System.out.println("res" + res); | ||
|
||
step.waitForEvent("wait-for-hello", "hello", "10m", "event.data.hello == async.data.hello"); | ||
|
||
int add = step.run("add-one-hundred", () -> { | ||
System.out.println("-> running step 2 :) " + (res != null ? res.sum : "")); | ||
return (res != null ? res.sum : 0) + 100; | ||
}, Integer.class); | ||
|
||
step.sleep("wait-one-sec", Duration.ofSeconds(2)); | ||
|
||
step.run("last-step", () -> (res != null ? res.sum : 0) * add, Integer.class); | ||
|
||
HashMap<String, String> data = new HashMap<String, String>() {{ | ||
put("hello", "world"); | ||
}}; | ||
step.sendEvent("followup-event-id", new InngestEvent(followUpEvent, data)); | ||
|
||
return new HashMap<String, String>() {{ | ||
put("message", "cool - this finished running"); | ||
}}; | ||
}; | ||
|
||
FunctionTrigger followupFnTrigger = new FunctionTrigger(followUpEvent, null, null); | ||
FunctionOptions followupFnConfig = new FunctionOptions( | ||
"fn-follow-up", | ||
"Follow up function!", | ||
new FunctionTrigger[]{followupFnTrigger} | ||
); | ||
Function2<FunctionContext, Step, LinkedHashMap<String, Object>> followupHandler = (ctx, step) -> { | ||
System.out.println("-> follow up handler called " + ctx.getEvent().getName()); | ||
return ctx.getEvent().getData(); | ||
}; | ||
|
||
HashMap<String, InngestFunction> functions = new HashMap<>(); | ||
functions.put("fn-id-slug", new InngestFunction(fnConfig, handler)); | ||
functions.put("fn-follow-up", new InngestFunction(followupFnConfig, followupHandler)); | ||
|
||
return functions; | ||
} | ||
|
||
@Bean | ||
public Inngest inngestClient() { | ||
return new Inngest("spring_example"); | ||
} | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/DemoController.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,10 @@ | ||
package com.inngest.springbootdemo; | ||
|
||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import com.inngest.springboot.InngestController; | ||
|
||
@RestController | ||
@RequestMapping(value = "/api/inngest") | ||
public class DemoController extends InngestController { | ||
} |
85 changes: 0 additions & 85 deletions
85
inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/InngestSingleton.java
This file was deleted.
Oops, something went wrong.
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