Skip to content

Commit

Permalink
Replace various hardcoded strings that can come from config (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertchae authored Feb 28, 2024
1 parent a62117b commit 5492d1d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
40 changes: 20 additions & 20 deletions inngest-core/src/main/kotlin/com/inngest/Comm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,13 @@ class CommHandler(

private fun getFunctionConfigs(): List<FunctionConfig> {
val configs: MutableList<FunctionConfig> = mutableListOf()
functions.forEach { entry -> configs.add(entry.value.getFunctionConfig()) }
functions.forEach { entry -> configs.add(entry.value.getFunctionConfig(getServeUrl())) }
return configs
}

fun register(): String {
val registrationUrl = "${config.baseUrl()}/fn/register"
// TODO use name from ServeConfig, framework from adapter, serveOrigin from ServeConfig
val requestPayload =
RegistrationRequestPayload(
appName = "my-app",
framework = "ktor",
sdk = "inngest-kt",
url = "http://localhost:8080/api/inngest",
v = Version.getVersion(),
functions = getFunctionConfigs(),
)
val requestPayload = getRegistrationRequestPayload()

val httpClient = client.httpClient

Expand Down Expand Up @@ -150,15 +141,24 @@ class CommHandler(
}

fun introspect(): String {
val requestPayload =
RegistrationRequestPayload(
appName = "my-app",
framework = "ktor",
sdk = "inngest-kt",
url = "http://localhost:8080/api/inngest",
v = Version.getVersion(),
functions = getFunctionConfigs(),
)
val requestPayload = getRegistrationRequestPayload()
return Klaxon().toJsonString(requestPayload)
}

private fun getRegistrationRequestPayload(): RegistrationRequestPayload {
return RegistrationRequestPayload(
appName = config.appId(),
framework = framework.toString(),
sdk = "inngest-kt",
url = getServeUrl(),
v = Version.getVersion(),
functions = getFunctionConfigs(),
)
}

private fun getServeUrl(): String {
val serveOrigin = config.serveOrigin() ?: "http://localhost:8080"
val servePath = config.servePath() ?: "/api/inngest"
return "$serveOrigin$servePath"
}
}
8 changes: 5 additions & 3 deletions inngest-core/src/main/kotlin/com/inngest/Function.kt
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ open class InngestFunction(
}
}

fun getFunctionConfig(): FunctionConfig {
fun getFunctionConfig(serveUrl: String): FunctionConfig {
// TODO use URL objects instead of strings so we can fetch things like scheme
val scheme = serveUrl.split("://")[0]
return FunctionConfig(
id = config.id,
name = config.name,
Expand All @@ -211,10 +213,10 @@ open class InngestFunction(
),
runtime =
hashMapOf(
"type" to "http",
"type" to scheme,
// TODO - Create correct URL
"url" to
"http://localhost:8080/api/inngest?fnId=${config.id}&stepId=step",
"$serveUrl?fnId=${config.id}&stepId=step",
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void shouldReturnSyncPayload() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType("application/json"))
.andExpect(header().string(InngestHeaderKey.Framework.getValue(), "springboot"))
.andExpect(jsonPath("$.appName").value("my-app"))
.andExpect(jsonPath("$.appName").value("spring_test_demo"))
.andExpect(jsonPath("$.sdk").value("inngest-kt"));
}
}

0 comments on commit 5492d1d

Please sign in to comment.