Skip to content

Commit

Permalink
Fixed and rebased
Browse files Browse the repository at this point in the history
- moved Array -> List conversion out of scope of this PR, we can do that
  in a follow up
  • Loading branch information
albertchae committed Sep 12, 2024
1 parent 9b5e153 commit 5180111
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.inngest.*;
import org.jetbrains.annotations.NotNull;

import java.util.LinkedHashMap;
import java.util.Map;

public class FollowupFunction extends InngestFunction {

Expand All @@ -18,7 +18,7 @@ public InngestFunctionConfigBuilder config(InngestFunctionConfigBuilder builder)
}

@Override
public LinkedHashMap<String, Object> execute(@NotNull FunctionContext ctx, @NotNull Step step) {
public Map<String, Object> execute(@NotNull FunctionContext ctx, @NotNull Step step) {
System.out.println("-> follow up handler called " + ctx.getEvent().getName());
return ctx.getEvent().getData();
}
Expand Down
4 changes: 2 additions & 2 deletions inngest/src/main/kotlin/com/inngest/Comm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import java.io.IOException

data class ExecutionRequestPayload(
val ctx: ExecutionContext,
val event: Event,
val events: List<Event>,
val event: InngestEvent,
val events: List<InngestEvent>,
val steps: MemoizedState,
)

Expand Down
8 changes: 4 additions & 4 deletions inngest/src/main/kotlin/com/inngest/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ data class InngestEvent
@JvmOverloads
constructor(
val name: String,
val data: Any,
val data: Map<String, Any>,
@Json(serializeNull = false)
val user: Any? = null,
@Json(serializeNull = false)
Expand All @@ -38,7 +38,7 @@ data class InngestEvent
class InngestEventBuilder(
var id: String?,
var name: String?,
var data: Any?,
var data: Map<String, Any>?,
private var user: Any?,
private var ts: Long?,
private var v: String? = null,
Expand All @@ -53,7 +53,7 @@ class InngestEventBuilder(
return this
}

fun data(data: Any): InngestEventBuilder {
fun data(data: Map<String, Any>): InngestEventBuilder {
this.data = data
return this
}
Expand Down Expand Up @@ -91,6 +91,6 @@ class InngestEventBuilder(
* in the order of which they were included in the request
*/
data class SendEventsResponse(
val ids: List<String>,
val ids: Array<String>,
val status: Int,
)
4 changes: 2 additions & 2 deletions inngest/src/main/kotlin/com/inngest/Function.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ internal class InternalFunctionConfig
* Includes event(s) and other run information
*/
data class FunctionContext(
val event: Event,
val events: List<Event>,
val event: InngestEvent,
val events: List<InngestEvent>,
val runId: String,
val fnId: String,
val attempt: Int,
Expand Down
6 changes: 3 additions & 3 deletions inngest/src/main/kotlin/com/inngest/Inngest.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.inngest

import com.beust.klaxon.Klaxon
import java.io.IOException
import io.ktor.http.*
import java.net.ConnectException

class Inngest
Expand Down Expand Up @@ -47,13 +45,15 @@ class Inngest

val responseBody = response.body!!.charStream()
try {
val sendEventsResponse = Klaxon().parse<EventAPIResponse>(responseBody)
val sendEventsResponse = Klaxon().parse<SendEventsResponse>(responseBody)
if (sendEventsResponse != null) {
return@lambda sendEventsResponse
}
} catch (e: Exception) {
throw InngestSendEventInvalidResponseException(responseBody.toString())
}
// If we haven't successfully parsed and returned a valid SendEventsResponse
// by this point, throw an exception
throw InngestSendEventInvalidResponseException(responseBody.toString())
}
} catch (e: ConnectException) {
Expand Down
7 changes: 3 additions & 4 deletions inngest/src/main/kotlin/com/inngest/Step.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class StepInterruptSleepException(
class StepInterruptSendEventException(
id: String,
hashedId: String,
val eventIds: List<String>,
val eventIds: Array<String>,
) : StepInterruptException(id, hashedId, eventIds)

class StepInterruptInvokeException(
Expand Down Expand Up @@ -211,16 +211,15 @@ class Step(
val hashedId = state.getHashFromId(id)

try {
val stepState = state.getState<List<String>>(hashedId, "event_ids")
val stepState = state.getState<Array<String>>(hashedId, "event_ids")

if (stepState != null) {
return SendEventsResponse(stepState, 200)
}
throw Exception("step state expected sendEvent, got something else")
} catch (e: StateNotFound) {
val response = client.send(events)
//throw StepInterruptSendEventException(id, hashedId, response!!.ids)
throw StepInterruptSendEventException(id, hashedId, response.ids)
throw StepInterruptSendEventException(id, hashedId, response!!.ids)
}
}

Expand Down

0 comments on commit 5180111

Please sign in to comment.