From f042d5be9442198038f1b4f20fb31e8ddbe7d416 Mon Sep 17 00:00:00 2001 From: Darwin D Wu Date: Thu, 23 Nov 2023 19:25:34 -0800 Subject: [PATCH] invoke failure handler for failure events --- lib/inngest/router/invoke.ex | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/inngest/router/invoke.ex b/lib/inngest/router/invoke.ex index c914def..a23b3e7 100644 --- a/lib/inngest/router/invoke.ex +++ b/lib/inngest/router/invoke.ex @@ -40,7 +40,6 @@ defmodule Inngest.Router.Invoke do ) do func = params - |> IO.inspect() |> load_functions() |> Enum.find(fn func -> Enum.member?(func.slugs(), fn_slug) @@ -85,7 +84,11 @@ defmodule Inngest.Router.Invoke do defp invoke(func, ctx, input) do try do - func.exec(ctx, input) |> SdkResponse.from_result([]) + if is_failure?(input) do + func.handle_failure(ctx, input) |> SdkResponse.from_result([]) + else + func.exec(ctx, input) |> SdkResponse.from_result([]) + end rescue non_retry in Inngest.NonRetriableError -> SdkResponse.from_result({:error, non_retry}, retry: false, stacktrace: __STACKTRACE__) @@ -142,4 +145,7 @@ defmodule Inngest.Router.Invoke do {:error, error} end end + + defp is_failure?(%{event: %{name: "inngest/function.failed"}} = _input), do: true + defp is_failure?(_), do: false end