Skip to content

Commit

Permalink
allow failure function to be found
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin67 committed Nov 24, 2023
1 parent bac1189 commit 4e218bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 14 additions & 2 deletions lib/inngest/function.ex
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,26 @@ defmodule Inngest.Function do
|> List.first()
end

def slugs() do
failure = if failure_handler_defined?(__MODULE__), do: [failure_slug()], else: []
[slug()] ++ failure
end

def serve(path) do
handler =
if failure_handler_defined?(__MODULE__) do
id = "#{slug()}-failure"
id = failure_slug()

[
%{
id: id,
name: "#{name()} (failure)",
triggers: [%Trigger{event: "inngest/function.failed"}],
triggers: [
%Trigger{
event: "inngest/function.failed",
expression: "event.data.function_id == \"#{slug()}\""
}
],
steps: %{
step: %Step{
id: :step,
Expand Down Expand Up @@ -177,6 +187,8 @@ defmodule Inngest.Function do
defp failure_handler_defined?(mod) do
mod.__info__(:functions) |> Keyword.get(:handle_failure) == 2
end

defp failure_slug(), do: "#{slug()}-failure"
end
end

Expand Down
5 changes: 4 additions & 1 deletion lib/inngest/router/invoke.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ defmodule Inngest.Router.Invoke do
) do
func =
params
|> IO.inspect()
|> load_functions()
|> Enum.find(&(&1.slug() == fn_slug))
|> Enum.find(fn func ->
Enum.member?(func.slugs(), fn_slug)
end)

ctx = %Inngest.Function.Context{
attempt: Map.get(ctx, "attempt", 0),
Expand Down

0 comments on commit 4e218bb

Please sign in to comment.