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

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

Summary

Callbacks

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

Functions

Defines a normal execution block with a message that is non-deterministic.

Set a duration to pause the execution of your function.

Pauses the function execution until the specified DateTime.

Defines a deterministic execution block with a message.

Pause function execution until a particular event is received before continuing.

Callbacks

@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.Function.Trigger.t()

Returns the event name or schedule that triggers the function

Functions

Link to this function

register_step(mod, file, line, step_type, name, tags \\ [])

View Source
Link to this macro

run(message, var \\ quote do _ end, contents)

View Source (macro)

Defines a normal execution block with a message that is non-deterministic.

Meaning whenever Inngest asks the SDK to execute, the code block wrapped within run will always run, no pun intended.

Hence making it non deterministic, since each execution can yield a different result.

This is best for things that do not need idempotency. The result here will be passed on to the next execution unit.

Arguments

It accepts an optional map that includes

  • event
  • data

Expected output types

@spec :ok | {:ok, map()} | {:error, map()}

where the data is a map accumulated with outputs from previous executions.

Examples

run "non deterministic code block", %{event: event, data: data} do
  # do
  # something
  # here

  {:ok, %{result: result}}
end
Link to this macro

sleep(duration)

View Source (macro)

Set a duration to pause the execution of your function.

Valid durations are combination of

  • s - second
  • m - minute
  • h - hour
  • d - day

Examples

sleep "2s"
sleep "1d"
sleep "5m"
sleep "1h30m"
Link to this macro

sleep(message, var \\ quote do _ end, contents)

View Source (macro)

Pauses the function execution until the specified DateTime.

Expected valid datetime string formats are:

  • RFC3389
  • RFC1123
  • RFC882
  • UNIX
  • ANSIC
  • ISOdate

Examples

sleep "sleep until 2023-10-25", %{event: event, data: data} do
  # do something to caculate time

  # return the specified time that it should sleep until
  "2023-07-18T07:31:00Z"
end
Link to this macro

step(message, var \\ quote do _ end, contents)

View Source (macro)

Defines a deterministic execution block with a message.

This is exactly the same as Inngest.Function.run/3, except the code within the step blocks are always guaranteed to be executed once.

Subsequent calls to the SDK will not execute and uses the previously executed result.

If the code block returns an error or raised an exception, it will be retried.

Arguments

It accepts an optional map that includes

  • event
  • data

Expected output types

@spec :ok | {:ok, map()} | {:error, map()}

where the data is a map accumulated with outputs from previous executions.

Examples

step "idempotent code block", %{event: event, data: data} do
  # do
  # something
  # here

  {:ok, %{result: result}}
end
Link to this function

validate_datetime(datetime)

View Source
Link to this macro

wait_for_event(event_name, var \\ quote do _ end, contents)

View Source (macro)

Pause function execution until a particular event is received before continuing.

It returns the accepted event object or nil if the event is not received within the timeout.

The event name will be used as the key for storing the returned event for subsequent execution units.

Examples

wait_for_event "auth/signup.email.confirmed", %{event: event, data: data} do
  match = "user.id"
  [timeout: "1d", if: "event.#{match} == async.#{match}"]
end

# or in a shorter version
wait_for_event "auth/signup.email.confirmed", do: [timeout: "1d", match: "user.id"]