Register a function
Inside a worker,worker.registerFunction(id, handler) makes a function callable from anywhere in
the iii system. The id follows the service::name form; the handler receives the call’s payload
and returns the result.
- Node / TypeScript
- Python
- Rust
Triggering (Invoking) functions
A function runs when a trigger fires. The same function can be invoked from many trigger types at once: direct CLI calls (iii trigger), in-process SDK calls (worker.trigger), or bindings to
event-source workers like http, cron, queue, state, and iii-stream. All paths leave the handler
unchanged.
The two most common ways to invoke a function directly are from worker code with worker.trigger or
from the terminal with the command iii trigger. The engine routes the call to whatever worker
registered the function; no trigger registration is involved. The action field controls delivery:
by default the call waits for the function to return its result, or for the configured timeout to
fire. Pass a different TriggerAction to change that.
- CLI
- Node / TypeScript
- Python
- Rust
- Default (synchronous). No
actionset. The call waits for the function to return its result or for the configured timeout to fire. TriggerAction.Void(). Fire-and-forget. The call returns immediately; the function still runs but the caller doesn’t see the result.TriggerAction.Enqueue({ queue }). Provided by queue. Routes the invocation through a named queue with retries; the call returns once the message is enqueued.
Refer to Using iii/Namespaces for
more information on namespaces and triggering functions from a specific namespace.
Routing to a namespace
Workers and their associated functions can be namespaced. A function id is unique per namespace, not globally:state::get can be registered once in default, once in orders, and once in
analytics. Set namespace on the trigger invocation to pick one.
Resolution is strict. A call that names orders resolves there and nowhere else, and a call that
names none resolves in the namespace of the calling worker. A miss returns function_not_found
naming the namespaces where the id does exist.
iii trigger reaches default unless you pass --namespace <NS>. For calling across namespaces
from worker code, see Use namespaces.Functions can also be registered (or bound) to Triggers such as an
http request, a cron
schedule, a state change, and so on. To bind a function to an event source, see Triggers /
Register a trigger.Workers can provide their own
TriggerActions. Check each worker’s
documentation for the action types it offers.In Python, every blocking method has an awaitable twin (
trigger_async, shutdown_async,
create_channel_async) for use inside asyncio. See the Python SDK
reference.Trigger functions from the CLI
iii trigger is a useful development tool. Pass --help to any function to see its arguments and a
description of what it does:
iii trigger runs through the exact same code paths as the rest of the system, you can do
real work straight from the terminal: figure out what a function does, apply database modifications,
make state changes, or try any other manipulation or new code interactively. That makes it a useful
tool for development and debugging.
Request and response formats are what make
iii trigger <function> --help work. Functions can carry JSON
Schemas for their request payload and response shape. For how to create these schemas when
registering a function, see Creating Workers /
Functions.Common functions
A handful of functions ship with the iii engine and the standard workers. You’ll likely call them from almost every iii project. They look like any function you’d register yourself and are invoked the same way (viaiii trigger or worker.trigger). The
only thing special about them is that you didn’t have to register them.
Engine functions (engine::*)
The engine itself registers a small set of introspection and lifecycle functions. Full request and
response schemas are in the
engine protocol reference.
The engine also publishes two subscription triggers in the same family. Bind a function to one of
these to react to the registry changing:
Common workers
Each of these is published by a separate worker. Function ids, payload shapes, and per-function behaviour are in the worker’s own docs at workers.iii.dev:- State: KV-style state with scoped key namespaces (distinct from routing namespaces) and reactive triggers on create/update/delete. See state.
- Stream: Real-time push to connected clients over WebSocket. See iii-stream.
- Queue: Durable, ordered job processing with retries, concurrency limits, and a dead-letter queue. See queue.
- Pub/Sub: Lightweight in-engine topic subscription for fan-out without durability guarantees. See pubsub.
- Observability: Traces, logs, metrics, alerts, sampling rules, and rollups. See iii-observability.