View Source Inngest.Function behaviour (Inngest v0.2.1)

Module to be used within user code to setup an Inngest function. Making it servable and invokable.

Creating an Inngest function is as easy as using Inngest.Function. It creates the necessary attributes and handlers it needs to work with Inngest.

defmodule MyApp.Inngest.SomeJob do
  use Inngest.Function
  alias Inngest.{FnOpts, Trigger}

  @func %FnOpts{id: "my-func", name: "some job"}
  @trigger %Trigger{event: "job/foobar"}

  @impl true
  def exec(ctx, input) do
    {:ok, "hello world"}
  end

  # Optional handler to handle failures when the function fails
  # after all retries are exhausted.
  def handle_failure(ctx, %{step: step} = _args) do
    _ = step.run(ctx, "handle-failure", fn ->
      "Do something here"
    end)

    {:ok, "error handled"}
  end
end

Function Options

Assign Inngest.FnOpts to @func to configure the function. See Inngest.FnOpts to see what options are available.

Trigger

A trigger is causes a function to run. One of the following is required, and they're mutually exclusive.

event - string and/or expression - string

The name of the event that will trigger this event to run. We recommend it to name it with a prefix so it's a easier pattern to identify what it's for.

e.g. auth/signup.email.send

cron - string

A unix-cron compatible schedule string.

Optional timezone prefix, e.g. TZ=Europe/Paris 0 12 * * 5.

Summary

Callbacks

The method to be called when the Inngest function starts execution.

Returns the function name

Returns the function's human-readable ID, such as "sign-up-flow"

Returns the event name or schedule that triggers the function

Callbacks

@callback exec(Inngest.Function.Context.t(), Inngest.Function.Input.t()) ::
  {:ok, any()} | {:error, any()}

The method to be called when the Inngest function starts execution.

Only this method needs to be provided.

@callback name() :: String.t()

Returns the function name

@callback slug() :: String.t()

Returns the function's human-readable ID, such as "sign-up-flow"

@callback trigger() :: Inngest.Trigger.t()

Returns the event name or schedule that triggers the function