Skip to main content

Overview

Custom triggers allow you to invoke functions in response to external events like cron schedules, webhooks, message queues, or database changes. The SDK provides registerTriggerType to define reusable trigger types that can be registered multiple times with different configurations.

Trigger Architecture

1

Register a trigger type

Define the trigger type once with a unique ID and handler logic.
2

Register trigger instances

Create multiple trigger instances with different configurations.
3

Handle events

When an event occurs, your handler invokes the configured function via iii.call().

TriggerHandler Interface

Example: Cron Trigger

Example: Webhook Trigger

Example: Message Queue Trigger

Unregistering Triggers

Error Handling

If registerTrigger() throws an error, it’s communicated back to the engine:

Best Practices

Custom Trigger Checklist:
  • ✅ Validate config in registerTrigger() and throw descriptive errors
  • ✅ Store trigger state (jobs, connections) in a Map keyed by id
  • ✅ Clean up resources in unregisterTrigger() (stop jobs, close connections)
  • ✅ Handle errors when calling iii.call() - don’t let trigger crashes stop the process
  • ✅ Use callVoid for fire-and-forget triggers, call when you need results
  • ✅ Log trigger events for debugging (registration, execution, errors)
  • ✅ Consider idempotency - triggers may fire multiple times for the same event