Actor Lifecycle Hooks
Actor lifecycle hooks are rule events that fire at specific points in an actor's lifecycle. They allow you to validate operations, enforce business logic, and trigger automations tied to actor state changes.
Hook Timing
Hooks are organized by when they execute relative to the operation.
Before Hooks
Execute before the operation completes — can prevent it with a validation error:
OnOrderBeforeCreated— Before order is createdOnOrderBeforeDeleted— Before order is deletedOnPaymentBeforeCreated— Before payment is createdOnPaymentBeforeDeleted— Before payment is deletedOnTicketBeforeCreated— Before ticket is createdOnTicketBeforeDeleted— Before ticket is deletedOnSkuBeforeCreated— Before SKU is createdOnSkuBeforeDeleted— Before SKU is deletedOnAssetBeforeCreated— Before asset is createdOnAssetBeforeDeleted— Before asset is deleted
Use for: Validation, preventing invalid state
After Hooks
Execute after the operation completes — changes are persisted:
OnOrderCreated— After order is createdOnOrderDeleted— After order is deletedOnPaymentCreated— After payment is createdOnPaymentDeleted— After payment is deletedOnPaymentCapture— After payment is capturedOnTicketCreated— After ticket is createdOnTicketDeleted— After ticket is deletedOnTicketComplete— After ticket is completedOnTicketRejected— After ticket is rejectedOnSkuCreated— After SKU is createdOnSkuDeleted— After SKU is deletedOnAssetCreated— After asset is createdOnAssetDeleted— After asset is deleted
Use for: Automation, notifications, integrations
Command Hooks
Execute when commands are applied to an actor:
OnOrderCommands— When commands applied to orderOnPaymentCommands— When commands applied to paymentOnTicketCommands— When commands applied to ticketOnSkuCommands— When commands applied to SKUOnAssetCommands— When commands applied to asset
Use for: Cascading logic, deriving additional changes
Journal Hooks
Execute when journal entries are created:
OnOrderJournal— When order journal entry createdOnPaymentJournal— When payment journal entry created
Use for: Audit trail reactions, logging
Hooks by Actor Type
Order (6 hooks)
Payment (7 hooks)
OnPaymentBeforeCreatedOnPaymentCreatedOnPaymentBeforeDeletedOnPaymentDeletedOnPaymentCommandsOnPaymentCaptureOnPaymentJournal
Ticket (8 hooks)
OnTicketBeforeCreatedOnTicketCreatedOnTicketBeforeDeletedOnTicketDeletedOnTicketCommandsOnTicketCompleteOnTicketRejected
SKU (5 hooks)
Asset (5 hooks)
Execution Order
For a single actor operation, hooks execute in this sequence:
- Before hooks — can prevent the operation with a validation error
- Operation executes — entity created, commands applied
- Commands hooks — can add further commands
- Created/Deleted hooks — automation and notifications
- Journal hooks — if a journal entry was created
Example for creating an order:
OnOrderBeforeCreated— Validate the order- Order created in database
OnOrderCreated— Send confirmation emailOnOrderJournal— Log journal entry (if created)
Choosing the Right Hook
Use Before hooks when:
- Validating input before operations complete
- Preventing invalid state changes
- Checking business rule constraints
Use After hooks when:
- Sending notifications
- Triggering external integrations
- Creating related entities
- Scheduling follow-up work
Use Command hooks when:
- Deriving additional changes from commands
- Applying cascading updates
- Enforcing command combinations
Examples
Validation with a Before Hook
param input: OnOrderBeforeCreated
let hasValidDelivery = input.order.deliveries count > 0
from hasValidDelivery match
false |> {
effect = 'validationError'
code = 'NO_DELIVERY'
message = 'Order must have at least one delivery'
}Automation with an After Hook
param input: OnTicketComplete
from {
effect = 'messageActor'
actorType = 'order'
actorId = input.ticket.orderId
messages = [{
type = 'applyCommands'
body = {
commands = [{
type = 'addTag'
value = 'support-resolved'
}]
}
}]
}Cascading with a Command Hook
param input: OnOrderCommands
let hasCancellation = input.order.commands
any c => c.type = 'cancel'
from hasCancellation match
true |> {
effect = 'orderCommand'
type = 'addTag'
value = 'cancelled'
}See Also
- Rule Hooks — Overview of all hook families
- Rule Effects — Available effects
- Common Patterns — Recipe-style examples
- Runtime Reference — Detailed hook documentation