Behaviour for SDK middleware.
Middleware modules can implement any subset of the callbacks below. Configure
middleware on a client with use Inngest.Client, middleware: [...] or on an
individual function with middleware in Inngest.FnOpts.
Middleware entries run in registration order. Client-level entries run before function-level entries for function execution and step sends.
Entries may be modules or {module, opts} tuples:
use Inngest.Client,
id: "my-app",
funcs: [MyApp.Functions.Sync],
middleware: [
MyApp.Inngest.RequestLogger,
{MyApp.Inngest.TenantMiddleware, tenant_header: "x-tenant-id"}
]Hook Shape
Callbacks receive an args map and the middleware entry opts. Transform
hooks return the updated args map. Wrap hooks receive args.next, a
zero-arity function that continues the middleware chain, and return the
wrapped result.
Middleware modules only need to define the callbacks they use. All callbacks are optional, so a middleware can implement a single hook without defining no-op functions for the rest.
This follows the current TypeScript SDK middleware model while using Elixir behaviour modules instead of classes.
Summary
Callbacks
Runs once when memoization replay has ended for this request.
Runs when middleware is registered on a client or function.
Runs after function code completes successfully.
Runs after function code returns or raises an error.
Runs before fresh function code begins for this request.
Runs after a fresh step handler completes successfully.
Runs after a fresh step handler raises.
Runs before a fresh step handler executes.
Mutates the function context, input, and memoized step map for this request.
Mutates outbound events before they are sent to Inngest.
Mutates step metadata and arguments before the step ID is hashed.
Wraps the user function handler.
Wraps an incoming function request.
Wraps event sending.
Wraps a step request.
Wraps a fresh step handler.
Types
Callbacks
Runs once when memoization replay has ended for this request.
In this SDK this hook fires after function input transformation, before fresh function code starts.
Runs when middleware is registered on a client or function.
args.client contains the runtime client. args.function is nil for
client-level registration and the function module for function-level
registration.
Runs after function code completes successfully.
Runs after function code returns or raises an error.
Runs before fresh function code begins for this request.
Runs after a fresh step handler completes successfully.
Runs after a fresh step handler raises.
Runs before a fresh step handler executes.
Mutates the function context, input, and memoized step map for this request.
Return the updated args map with :ctx, :input, and :steps keys.
Mutates outbound events before they are sent to Inngest.
This hook runs for both Inngest.Client.send/2 and
Inngest.StepTool.send_event/3. Return the updated args map with an :events
key.
Mutates step metadata and arguments before the step ID is hashed.
Return the updated args map with :step_id, :step_type, :input, and
:options keys where applicable.
Wraps the user function handler.
args.next returns the function result tuple, such as {:ok, value} or
{:error, reason}.
Wraps an incoming function request.
args.request contains the framework request information when available and
args.next returns the generated SDK response.
@callback wrap_send_event(args(), opts()) :: Inngest.Client.send_result()
Wraps event sending.
args.next sends the events and returns the normal Inngest.Client.send/2
result tuple. Use this hook for metrics, backups, or result shaping around the
HTTP send.
Wraps a step request.
This hook runs for both fresh and memoized step values. args.next returns
the step value visible to user code.
Wraps a fresh step handler.
args.next executes the step body and returns its output. This hook does not
run for memoized step values.