diff --git a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/WithOnFailureFunction.java b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/WithOnFailureFunction.java index 6d2e6d72..4e9825db 100644 --- a/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/WithOnFailureFunction.java +++ b/inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/testfunctions/WithOnFailureFunction.java @@ -4,7 +4,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class WithOnFailureFunction extends InngestFunction implements WithFailureHandler { +public class WithOnFailureFunction extends InngestFunction { @NotNull @Override public InngestFunctionConfigBuilder config(InngestFunctionConfigBuilder builder) { diff --git a/inngest-spring-boot-demo/src/test/java/com/inngest/springbootdemo/WithOnFailureIntegrationTest.java b/inngest-spring-boot-demo/src/test/java/com/inngest/springbootdemo/WithOnFailureIntegrationTest.java index c45792f1..6a9647d7 100644 --- a/inngest-spring-boot-demo/src/test/java/com/inngest/springbootdemo/WithOnFailureIntegrationTest.java +++ b/inngest-spring-boot-demo/src/test/java/com/inngest/springbootdemo/WithOnFailureIntegrationTest.java @@ -19,11 +19,6 @@ @IntegrationTest @Execution(ExecutionMode.CONCURRENT) class WithOnFailureIntegrationTest { - @BeforeAll - static void setup(@Autowired CommHandler handler) { - handler.register("http://localhost:8080"); - } - @Autowired private DevServerComponent devServer; @@ -35,7 +30,7 @@ static void setup(@Autowired CommHandler handler) { @Test void testWithOnFailureShouldCallOnFailure() throws Exception { String eventName = "test/with-on-failure"; - String eventId = InngestFunctionTestHelpers.sendEvent(client, eventName).first(); + String eventId = InngestFunctionTestHelpers.sendEvent(client, eventName).getIds()[0]; Thread.sleep(sleepTime); diff --git a/inngest-test-server/src/main/kotlin/com/inngest/testserver/SlackFailureReport.kt b/inngest-test-server/src/main/kotlin/com/inngest/testserver/SlackFailureReport.kt index dff8684b..e0ed2ef5 100644 --- a/inngest-test-server/src/main/kotlin/com/inngest/testserver/SlackFailureReport.kt +++ b/inngest-test-server/src/main/kotlin/com/inngest/testserver/SlackFailureReport.kt @@ -2,9 +2,7 @@ package com.inngest.testserver import com.inngest.* -class SlackFailureReport : - InngestFunction(), - WithFailureHandler { +class SlackFailureReport : InngestFunction() { override fun config(builder: InngestFunctionConfigBuilder): InngestFunctionConfigBuilder = builder .id("always-fail-fn") diff --git a/inngest/src/main/kotlin/com/inngest/InngestFunction.kt b/inngest/src/main/kotlin/com/inngest/InngestFunction.kt index 81b9119f..f116dcdc 100644 --- a/inngest/src/main/kotlin/com/inngest/InngestFunction.kt +++ b/inngest/src/main/kotlin/com/inngest/InngestFunction.kt @@ -30,7 +30,9 @@ abstract class InngestFunction { } internal fun toFailureHandler(appId: String): InternalInngestFunction? { - if (this is WithFailureHandler) { + val onFailureMethod = this.javaClass.getMethod("onFailure", FunctionContext::class.java, Step::class.java) + + if (onFailureMethod.declaringClass != InngestFunction::class.java) { val fnConfig = buildConfig() val fullyQualifiedId = "$appId-${fnConfig.id}" val fnName = fnConfig.name ?: fnConfig.id @@ -45,4 +47,20 @@ abstract class InngestFunction { } return null } + + /** + * Provide a function to be called if your function fails, meaning + * that it ran out of retries and was unable to complete successfully. + * + * This is useful for sending warning notifications or cleaning up + * after a failure and supports all the same functionality as a + * regular handler. + * + * @param ctx The function context including event(s) that triggered the function + * @param step A class with methods to define steps within the function + */ + open fun onFailure( + ctx: FunctionContext, + step: Step, + ): Any? = null } diff --git a/inngest/src/main/kotlin/com/inngest/WithFailureHandler.kt b/inngest/src/main/kotlin/com/inngest/WithFailureHandler.kt deleted file mode 100644 index c154a910..00000000 --- a/inngest/src/main/kotlin/com/inngest/WithFailureHandler.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.inngest - -interface WithFailureHandler { - /** - * Function to call when the Inngest function fails. - * - * @param ctx The function context including event(s) that triggered the function - * @param step A class with methods to define steps within the function - */ - fun onFailure( - ctx: FunctionContext, - step: Step, - ): Any? -}