Inngest.FnOpts (Inngest v0.3.0)

Copy Markdown View Source

Function configuration options.

See the typespec for all available options.

Summary

Types

Configure how the function should consume batches of events (reference)

Define an event that can be used to cancel a running or sleeping function (reference)

Limit the number of concurrently running functions (reference)

Options to configure function debounce (reference).

A unique identifier for your function. This should not change between deploys.

A key expression which is used to prevent duplicate events from triggering a function more than once in 24 hours.

A name for your function. If defined, this will be shown in the UI as a friendly display name instead of the ID.

Prioritize specific function runs ahead of others (reference)

Options to configure how to rate limit function execution (reference)

Configure the number of times the function will be retried from 0 to 20. Default: 3

Ensure only one run per key executes at a time.

t()

Throttle function execution to a given number of runs per period.

Controls how long a function has to start and finish execution.

Types

batch_events()

@type batch_events() ::
  %{max_size: number(), timeout: binary(), key: binary() | nil} | nil

Configure how the function should consume batches of events (reference)

max_size - number required

The maximum number of events a batch can have. Current limit is 100.

timeout - string required

How long to wait before invoking the function with the batch even if it's not full. Current permitted values are from 1s to 60s.

cancel_on()

@type cancel_on() :: cancel_option() | [cancel_option()] | nil

Define an event that can be used to cancel a running or sleeping function (reference)

event - string required

The event name which will be used to cancel

match - string optional

The property to match the event trigger and the cancelling event, using dot-notation e.g. data.userId

if - string optional

TODO

timeout - string optional

The amount of time to wait to receive the cancelling event. e.g. 30m, 3h, or 2d

cancel_option()

@type cancel_option() :: %{
  event: binary(),
  match: binary() | nil,
  if: binary() | nil,
  timeout: binary() | nil
}

concurrency()

@type concurrency() :: number() | concurrency_option() | [concurrency_option()] | nil

Limit the number of concurrently running functions (reference)

limit - string required

The maximum number of concurrently running steps.

key - string optional

A unique key expression for which to restrict concurrently running steps to. The expression is evaluated for each triggering event and a unique key is generate.

concurrency_option()

@type concurrency_option() ::
  %{limit: number(), key: binary() | nil, scope: binary() | nil} | nil

debounce()

@type debounce() :: %{key: binary() | nil, period: binary()} | nil

Options to configure function debounce (reference).

period - string required

The time period of which to set the limit. The period begins when the first matching event is received. How long to wait before invoking the function with the batch even if it's not full. Current permitted values are from 1s to 7d (168h).

key - string optional

A unique key expression to apply the debounce to. The expression is evaluated for each triggering event.

Expressions are defined using the Common Expression Language (CEL) with the original event accessible using dot-notation. Examples:

  • Debounce per customer id: event.data.customer_id
  • Debounce per account and email address: event.data.account_id + "-" + event.user.email

id()

@type id() :: binary()

A unique identifier for your function. This should not change between deploys.

idempotency()

@type idempotency() :: binary() | nil

A key expression which is used to prevent duplicate events from triggering a function more than once in 24 hours.

This is equivalent to setting rate_limit with a key, a limit of 1 and period of 24hr.

Expressions are defined using the Common Expression Language (CEL) with the original event accessible using dot-notation. Examples:

  • Only run once for each customer id: event.data.customer_id
  • Only run once for each account and email address: event.data.account_id + "-" + event.user.email

middleware()

@type middleware() :: [Inngest.Middleware.entry()]

name()

@type name() :: binary() | nil

A name for your function. If defined, this will be shown in the UI as a friendly display name instead of the ID.

priority()

@type priority() :: %{run: binary() | nil} | nil

Prioritize specific function runs ahead of others (reference)

run - string optional

An expression which must return an integer between -600 and 600 (by default), with higher return values resulting in a higher priority. See reference for more information.

rate_limit()

@type rate_limit() :: %{limit: number(), period: binary(), key: binary() | nil} | nil

Options to configure how to rate limit function execution (reference)

limit - number required

The maximum number of functions to run in the given time period.

period - number required

The time period of which to set the limit. The period begins when the first matching event is received. How long to wait before invoking the function with the batch even if it's not full. Current permitted values are from 1s to 60s.

key - string optional

A unique key expression to apply the limit to. The expression is evaluated for each triggering event.

Expressions are defined using the Common Expression Language (CEL) with the original event accessible using dot-notation. Examples:

  • Rate limit per customer id: event.data.customer_id
  • Rate limit per account and email address: event.data.account_id + "-" + event.user.email

Note

This option cannot be used with cancel_on and rate_limit.

retries()

@type retries() :: number() | nil

Configure the number of times the function will be retried from 0 to 20. Default: 3

singleton()

@type singleton() :: %{key: binary() | nil, mode: :skip | :cancel} | nil

Ensure only one run per key executes at a time.

mode - atom required

Determines what happens when a new run is triggered while one is already active. Must be :skip or :cancel.

key - string optional

A unique key expression to partition singleton groups.

t()

@type t() :: %Inngest.FnOpts{
  batch_events: batch_events(),
  cancel_on: cancel_on(),
  concurrency: concurrency(),
  debounce: debounce(),
  id: id(),
  idempotency: idempotency(),
  middleware: middleware(),
  name: name(),
  priority: priority(),
  rate_limit: rate_limit(),
  retries: retries(),
  singleton: singleton(),
  throttle: throttle(),
  timeouts: timeouts()
}

throttle()

@type throttle() ::
  %{
    key: binary() | nil,
    limit: number(),
    period: binary(),
    burst: number() | nil
  }
  | nil

Throttle function execution to a given number of runs per period.

limit - number required

The maximum number of runs to allow per the given period.

period - string required

The time period over which the limit applies.

key - string optional

A unique key expression to partition throttle groups.

burst - number optional

Burst capacity beyond the steady-state rate.

timeouts()

@type timeouts() :: %{start: binary() | nil, finish: binary() | nil} | nil

Controls how long a function has to start and finish execution.

start - string optional

Maximum time from trigger to the first execution attempt.

finish - string optional

Maximum total time for the function run to complete.