-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add extendable controller & configuration for setup #28
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
82 changes: 82 additions & 0 deletions
82
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,82 @@ | ||
package com.inngest.springbootdemo; | ||
|
||
|
||
import com.inngest.*; | ||
import com.inngest.springboot.InngestConfiguration; | ||
import kotlin.jvm.functions.Function2; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we already discussed this but probably ideal if we don't have to pull in a kotlin Function here and can instead use lambdas (available in Java 8) or something like https://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html |
||
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", null); | ||
|
||
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; | ||
} | ||
|
||
@Override | ||
public Inngest inngestClient() { | ||
return new Inngest("spring_demo"); | ||
} | ||
} | ||
|
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
20 changes: 20 additions & 0 deletions
20
inngest-spring-boot-demo/src/test/java/com/inngest/springbootdemo/DemoTestConfiguration.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,20 @@ | ||
package com.inngest.springbootdemo; | ||
|
||
import com.inngest.Inngest; | ||
import com.inngest.InngestFunction; | ||
import com.inngest.springboot.InngestConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
import java.util.HashMap; | ||
|
||
public class DemoTestConfiguration extends InngestConfiguration { | ||
@Override | ||
protected HashMap<String, InngestFunction> functions() { | ||
return new HashMap<>(); | ||
} | ||
|
||
@Override | ||
protected Inngest inngestClient() { | ||
return new Inngest("spring_test_demo"); | ||
} | ||
} |
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
Oops, something went wrong.
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.
probably best to version all the subpackages of
inngest-kt
together. I think there's something we can add in the root gradle file. I'll take a note of this for now