Skip to content
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

Fix CommHandler instantiation from spring boot #37

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion inngest-core/src/main/kotlin/com/inngest/Function.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ open class InngestFunction(
val config: FunctionOptions,
val handler: (ctx: FunctionContext, step: Step) -> Any?,
) {
constructor(config: FunctionOptions, handler: BiFunction<FunctionContext, Step, out Any>, a: Int) : this(
constructor(config: FunctionOptions, handler: BiFunction<FunctionContext, Step, out Any>) : this(
config,
handler.toKotlin(),
)
Expand Down
96 changes: 49 additions & 47 deletions inngest-core/src/main/kotlin/com/inngest/ServeConfig.kt
Original file line number Diff line number Diff line change
@@ -1,61 +1,63 @@
package com.inngest

class ServeConfig(
val client: Inngest,
private val id: String? = null,
private val signingKey: String? = null,
private val serveOrigin: String? = null,
private val servePath: String? = null,
// streaming: String = "false" // probably can't stream yet
private val logLevel: String? = null,
private val baseUrl: String? = null,
) {
fun appId(): String {
if (id != null) return id
return client.appId
}

fun signingKey(): String {
if (signingKey != null) return signingKey
class ServeConfig
@JvmOverloads
constructor(
val client: Inngest,
private val id: String? = null,
private val signingKey: String? = null,
private val serveOrigin: String? = null,
private val servePath: String? = null,
// streaming: String = "false" // probably can't stream yet
private val logLevel: String? = null,
private val baseUrl: String? = null,
) {
fun appId(): String {
if (id != null) return id
return client.appId
}

return when (client.env) {
InngestEnv.Dev -> "test"
else -> {
val signingKey = System.getenv(InngestSystem.SigningKey.value)
if (signingKey == null) {
throw Exception("signing key is required")
fun signingKey(): String {
if (signingKey != null) return signingKey

return when (client.env) {
InngestEnv.Dev -> "test"
else -> {
val signingKey = System.getenv(InngestSystem.SigningKey.value)
if (signingKey == null) {
throw Exception("signing key is required")
}
signingKey
}
signingKey
}
}
}

fun baseUrl(): String {
if (baseUrl != null) return baseUrl
fun baseUrl(): String {
if (baseUrl != null) return baseUrl

val url = System.getenv(InngestSystem.EventApiBaseUrl.value)
if (url != null) {
return url
}
val url = System.getenv(InngestSystem.EventApiBaseUrl.value)
if (url != null) {
return url
}

return when (client.env) {
InngestEnv.Dev -> "http://127.0.0.1:8288"
else -> "https://api.inngest.com"
return when (client.env) {
InngestEnv.Dev -> "http://127.0.0.1:8288"
else -> "https://api.inngest.com"
}
}
}

fun serveOrigin(): String? {
if (serveOrigin != null) return serveOrigin
return System.getenv(InngestSystem.ServeOrigin.value)
}
fun serveOrigin(): String? {
if (serveOrigin != null) return serveOrigin
return System.getenv(InngestSystem.ServeOrigin.value)
}

fun servePath(): String? {
if (servePath != null) return servePath
return System.getenv(InngestSystem.ServePath.value)
}
fun servePath(): String? {
if (servePath != null) return servePath
return System.getenv(InngestSystem.ServePath.value)
}

fun logLevel(): String {
if (logLevel != null) return logLevel
return System.getenv(InngestSystem.LogLevel.value) ?: "info"
fun logLevel(): String {
if (logLevel != null) return logLevel
return System.getenv(InngestSystem.LogLevel.value) ?: "info"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.inngest.springboot;

import com.inngest.CommHandler;
import com.inngest.Inngest;
import com.inngest.InngestFunction;
import com.inngest.SupportedFrameworkName;
import com.inngest.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

Expand All @@ -19,6 +16,8 @@ public abstract class InngestConfiguration {

@Bean
protected CommHandler commHandler(@Autowired Inngest inngestClient) {
return new CommHandler(functions(), inngestClient, frameworkName);
// TODO: Add missing configuration
ServeConfig serveConfig = new ServeConfig(inngestClient);
return new CommHandler(functions(), inngestClient, serveConfig, frameworkName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public HashMap<String, InngestFunction> functions() {
};

HashMap<String, InngestFunction> functions = new HashMap<>();
functions.put("fn-id-slug", new InngestFunction(fnConfig, handler,1));
functions.put("fn-follow-up", new InngestFunction(followupFnConfig, followupHandler,2));
functions.put("fn-id-slug", new InngestFunction(fnConfig, handler));
functions.put("fn-follow-up", new InngestFunction(followupFnConfig, followupHandler));

return functions;
}
Expand Down
Loading