Skip to content

Commit

Permalink
invoke failure handler for failure events
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin67 committed Nov 24, 2023
1 parent 4e218bb commit f042d5b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/inngest/router/invoke.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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__)
Expand Down Expand Up @@ -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

0 comments on commit f042d5b

Please sign in to comment.