Skip to main content

Overview

Triggers are event sources that automatically invoke functions when specific conditions occur. The III Engine provides built-in trigger types (HTTP endpoints, scheduled jobs, system events) and supports custom trigger types implemented by workers.

Trigger Registration

Register a trigger to connect an event source to a function:
Trigger registration message:

Registration Flow

Implementation:

HTTP Triggers

HTTP triggers expose functions as REST API endpoints:

Basic HTTP Endpoint

HTTP request structure:

Path Parameters

Capture dynamic segments from URL:
Example from tests:

Query Parameters

Request Body

Parse JSON body automatically:

Custom Response Headers

HTTP trigger handlers receive an ApiRequest and must return an ApiResponse with status_code, optional body, and optional headers.

Event Triggers

The Engine provides system event triggers:

Functions Available Event

Triggered when function registry changes (functions added/removed):
Implementation detail:
The SDK creates an internal function and trigger automatically. See packages/node/iii/src/iii.ts:393-428.

Log Events

Receive OpenTelemetry log events from the Engine:
OtelLogEvent structure:
Severity levels:

Schedule Triggers

Schedule triggers are handled by the Engine’s scheduler. Configuration format depends on Engine implementation (cron expressions, intervals, etc.).
Example pattern:

Custom Trigger Types

Workers can implement custom trigger types for any event source:

Implementing a Trigger Handler

TriggerHandler interface:

Registering Trigger Types

Register your custom trigger type with the Engine:
Implementation:

Trigger Registration Result

The Engine sends confirmation after trigger registration:
Possible error codes:
  • trigger_type_not_found - Trigger type not registered
  • trigger_registration_failed - Handler threw exception

Real-World Examples

API Helper Hook

Simplify HTTP trigger registration:
Usage:

Database Change Trigger

Custom trigger for database changes:

Trigger Lifecycle

1

Registration

Worker sends RegisterTrigger message to Engine with type, function_id, and config
2

Handler Invocation

Engine invokes the trigger type’s registerTrigger handler (if custom type)
3

Event Source Setup

Handler sets up event listener, webhook server, scheduler, etc.
4

Active

Trigger invokes function when events occur
5

Unregistration

Worker calls trigger.unregister() or disconnects, Handler’s unregisterTrigger is called

Multi-Language Support

Next Steps

Functions

Learn about function registration and invocation

Channels

Stream data between functions