Skip to content

Commit

Permalink
Add a Kotlin function example that has a failure handler
Browse files Browse the repository at this point in the history
  • Loading branch information
KiKoS0 committed Aug 25, 2024
1 parent 82c0acb commit d97c93a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fun Application.module() {
RestoreFromGlacier(),
ProcessUserSignup(),
TranscodeVideo(),
SlackFailureReport(),
),
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.inngest.testserver

import com.inngest.*

class SlackFailureReport :
InngestFunction(),
WithFailureHandler {
override fun config(builder: InngestFunctionConfigBuilder): InngestFunctionConfigBuilder =
builder
.id("always-fail-fn")
.name("Always Fail Function")
.triggerEvent("always-fail-fn")

override fun execute(
ctx: FunctionContext,
step: Step,
): String {
step.run("throw exception") {
throw RuntimeException("This function always fails")
"Step result"
}

return "Success"
}

override fun onFailure(
ctx: FunctionContext,
step: Step,
): String {
step.run("send slack message") {
"Sending a message to Slack"
}

return "onFailure Success"
}
}

0 comments on commit d97c93a

Please sign in to comment.