Lifecycle Events
Respond to publishing transitions, updates, and events using hooks and durable outbox notifications.
Lifecycle events let you connect external services, sync search indexes, or send Slack notifications in response to workflow transitions and publication changes.
Outbox Architecture
When you update or transition a document, Dyrected writes the document changes and the corresponding outbox event to the database in a single atomic transaction. This guarantees that events are never lost, even if an external handler is down.
A background worker periodically scans the __lifecycle_events table and dispatches pending events with an exponential back-off strategy.
Event Names
Dyrected publishes the following standard lifecycle events:
| Event Name | Trigger | Payload |
|---|---|---|
revision.created | A draft or new entry is saved | { revision, previousRevision } |
workflow.transitioned | An entry goes through a workflow transition | { transition, from, to, revision, comment } |
entry.published | An entry enters a state marked published: true | { revision } |
entry.unpublished | An entry transitions out of a published state | { revision } |
Configuring Handlers
Register event handlers in your main configuration under the events property:
import { defineConfig } from "@dyrected/core"
export default defineConfig({
collections: [...],
globals: [...],
events: {
maxAttempts: 5,
retryDelayMs: 2000,
handlers: [
async (event) => {
if (event.name === "entry.published") {
console.log(`Entry ${event.documentId} in ${event.collection} is live!`)
}
}
]
}
})