Scheduled Events
Schedule events to fire in the future. Reminders, expirations, delayed notifications -- anything that shouldn't happen immediately.
How it works
When an event is written, your spec can schedule a future event:
User adds item to cart -> Schedule "send reminder" in 24 hours
(unless cart is checked out first)
If the cart is checked out within 24 hours, the reminder is automatically canceled. If not, the reminder event fires.
Spec syntax
Add a schedule block to any event's implications:
{
"aggregate_types": {
"cart": {
"events": {
"had_item_added": {
"schema": {
"type": "object",
"properties": {
"product_id": {
"type": "string"
}
}
},
"handler": [
{
"append": {
"target": "items",
"value": "$.data"
}
}
],
"implications": [
{
"schedule": {
"delay": "24h",
"emit": {
"aggregate_type": "notification",
"id": "$.metadata.actor.id",
"event_type": "cart_abandonment_reminder",
"data": {
"cart_id": "$.key"
}
},
"cancel_on": [
{
"aggregate_type": "cart",
"id": "$.key",
"event_type": "was_checked_out"
}
]
}
}
]
},
"was_checked_out": {
"schema": {
"type": "object"
},
"handler": [
{
"set": {
"target": "checked_out",
"value": true
}
}
]
}
}
},
"notification": {
"events": {
"cart_abandonment_reminder": {
"allow_skip_occ": true,
"schema": {
"type": "object",
"properties": {
"cart_id": {
"type": "string"
}
},
"required": [
"cart_id"
]
},
"handler": [
{
"set": {
"target": "",
"value": "$.data"
}
}
]
}
}
}
},
"agent_types": [
"user"
]
}
Fields
| Field | Required | Description |
|---|---|---|
delay |
Yes | How long to wait before firing. See delay formats. |
emit |
Yes | The event to emit when the delay expires. |
cancel_on |
No | Events that cancel this scheduled event before it fires. |
if_missing |
No | "create" (default) or "skip" when the target stream does not exist at delivery. |
Delay formats
| Format | Duration | Example |
|---|---|---|
"Ns" |
N seconds | "30s" = 30 seconds |
"Nm" |
N minutes | "30m" = 30 minutes |
"Nh" |
N hours | "24h" = 24 hours |
"Nd" |
N days | "7d" = 7 days |
Use the string delay field in your spec; delay_ms is not supported spec syntax.
Minimum delay: 5 minutes. Scheduled events are designed for coarse-grained business logic, not real-time operations. Delays under 5 minutes are rejected at spec validation time.
Target event requirements
The target aggregate type and event must be declared in the same spec. The
receiving event must declare "allow_skip_occ": true, as shown for
notification.cart_abandonment_reminder above. Deployment rejects schedules
whose targets do not meet these requirements.
Avoid creating missing targets
Schedules create their target aggregate when it is missing by default. For an
expiry or reminder that should apply only to an existing stream, set
"if_missing": "skip" inside schedule:
{"schedule": {"delay": "1h", "if_missing": "skip", "emit": {
"aggregate_type": "session", "id": "$.id",
"event_type": "should_expire", "data": {}
}}}
Existence means the target stream contains an event. The check is atomic with
delivery. A missing target produces no event or aggregate: the timer becomes
skipped, with skip_reason: "target_missing" and a skipped_at timestamp.
It is not retried or dead-lettered.
This does not test your aggregate's business state. An ordinary deletion event still leaves an existing stream. To handle renewed sessions or reused IDs, include a generation or expiry token and check it in your event handler.
Changing a spec with pending timers
Spec deployment and validation return pending_timer_compatibility alongside
the existing warnings array. The report identifies removed target types or
events, loss of allow_skip_occ, and incompatible event data. It includes
status (compatible, incompatible, or unavailable), instance_id,
environment, snapshot, pending_count, incompatible_count, reasons,
and up to ten examples. Counts are null when coverage is unavailable.
The default pending_timer_policy: "warn" permits deployment with warnings.
Use pending_timer_policy: "reject" in the deployment or validation request to
return HTTP 409 for incompatible pending work, or 503 if it cannot be checked.
Invalid policy values return 422. Cancel or replace incompatible timers before
retrying a strict deployment.
The check is a bounded snapshot of pending timers for that instance and environment. It does not prevent new schedules after the check, pin timers to an older spec, or cancel them. Timers continue to use the live spec at delivery.
The emit block
The emit block defines what event fires when the delay expires:
{
"emit": {
"aggregate_type": "notification",
"id": "$.metadata.actor.id",
"event_type": "reminder_sent",
"data": {
"original_cart": "$.key",
"user_name": "$.data.user_name"
}
}
}
aggregate_type- Target aggregate type (string literal)id- Target aggregate ID (JSONPath or string literal)event_type- Event type to emit (string literal)data- Event payload (values can be JSONPath expressions)
JSONPath expressions are resolved at scheduling time against the triggering event.
Cancel conditions
Cancel conditions specify which future events should cancel this scheduled event:
{
"cancel_on": [
{
"aggregate_type": "order",
"id": "$.key",
"event_type": "was_completed"
},
{
"aggregate_type": "order",
"id": "$.key",
"event_type": "was_cancelled"
}
]
}
When any matching event is written, the scheduled event is canceled. All three
fields must match. The id may be a literal or an expression that resolves to
either the bare aggregate ID or the full key, such as cart:<id>. Expressions
are resolved when scheduling, so $.key can refer to the triggering aggregate.
Race condition warning
There is an inherent race between firing and cancellation. If a cancel event arrives at nearly the same moment the scheduled event is due to fire, the cancellation may not prevent the scheduled event from firing.
Make the receiving event safe when it arrives after the condition has changed. For mutually exclusive business actions, enforce the condition with aggregate concurrency preconditions, or use an atomic write when the condition spans multiple aggregates. Scheduling alone does not make those actions mutually exclusive.
Fired event metadata
When a scheduled event fires, it includes metadata for audit trails:
{
"key": "notification:user123",
"type": "cart_abandonment_reminder",
"data": {"cart_id": "cart:abc"},
"metadata": {
"timestamp": 1705312800,
"actor": {
"type": "system_agent",
"id": "event_scheduler"
},
"implied_by": {
"key": "cart:abc",
"event_type": "had_item_added",
"depth": 1
},
"scheduled": {
"scheduled_id": "a1b2c3d4-e5f6-...",
"fire_at": "2024-01-15T12:00:00Z"
}
}
}
actor.typeis"system_agent"-- a reserved actor type for system operations that bypasses normalagent_typesvalidationactor.idis"event_scheduler"-- identifies this as a scheduled eventimplied_byreferences the original triggering eventscheduledcontains scheduling metadata
Use cases
Trial expiration
{
"was_activated": {
"handler": [{"set": {"target": "", "value": "$.data"}}],
"implications": [
{
"schedule": {
"delay": "14d",
"emit": {
"aggregate_type": "subscription",
"id": "$.data.user_id",
"event_type": "trial_should_expire",
"data": {"user_id": "$.data.user_id"}
},
"cancel_on": [
{
"aggregate_type": "subscription",
"id": "$.data.user_id",
"event_type": "was_converted"
}
]
}
}
]
}
}
User converts to paid? Expiration cancels automatically.
Subscription renewal
{
"was_activated": {
"handler": [{"set": {"target": "", "value": "$.data"}}],
"implications": [
{
"schedule": {
"delay": "30d",
"emit": {
"aggregate_type": "billing",
"id": "$.metadata.actor.id",
"event_type": "renewal_due",
"data": {
"subscription_id": "$.key",
"plan": "$.data.plan"
}
},
"cancel_on": [
{
"aggregate_type": "subscription",
"id": "$.key",
"event_type": "was_cancelled"
}
]
}
}
]
}
}
Recurring events
j17 doesn't natively support cron-like recurring events. Build recurrence by rescheduling -- each event schedules the next:
{
"weekly_report_sent": {
"handler": [{"set": {"target": "last_sent", "value": "$.metadata.timestamp"}}],
"implications": [
{
"schedule": {
"delay": "7d",
"emit": {
"aggregate_type": "reports",
"id": "global",
"event_type": "should_send_weekly",
"data": {}
}
}
}
]
}
}
Inspect and manage scheduled events
Use the instance dashboard's Scheduled Events and Dead Letters sections to inspect timers in the selected environment. Timers from other environments are kept separate.
The console API uses a control-plane bearer token. Instance viewers can list
timers; instance administrators can cancel or retry them. Scoped bearer tokens
must include the instances scope. Instance write/deploy API keys do not
authorize these operations.
To inspect skipped timers, request
GET /api/instances/:id/ops/:environment/scheduled?status=skipped with the same
authentication. The default listing selects pending timers. Skipped records
include their missing-target policy and terminal reason.
Cancel a scheduled event
POST /api/instances/:id/ops/:environment/scheduled/:scheduled_id/cancel
Authorization: Bearer <control-plane-token>
Cancel pending or dead-lettered work to prevent another delivery attempt. Canceling already-canceled work succeeds again. A timer that has already fired cannot be canceled, and this operation does not undo its event.
Retry a dead letter
POST /api/instances/:id/ops/:environment/scheduled/:scheduled_id/retry
Authorization: Bearer <control-plane-token>
Only dead-lettered events can be retried. Retry returns the timer to pending with its failure count reset. A canceled event cannot be retried.
Both actions apply only to the selected instance and environment. A successful
console API action returns HTTP 201 with ok: true; an operation refused by the
service returns HTTP 422 with an error. Authentication and authorization errors
are reported separately.
Error handling
If a scheduled event fails to fire (e.g., spec not deployed, validation error), it is retried on the next poll cycle. After 10 failures, it moves to dead_letter status.
Dead-lettered events remain available for inspection, include last_error with the failure reason, and can be retried from the dashboard or console API.
| Error | Cause | Resolution |
|---|---|---|
invalid_fire_at |
The timer has an invalid deadline | Inspect the timer and confirm its intended delivery time before retrying or recreating it. |
no_spec_deployed |
No spec in target environment | Deploy a spec |
| Schema validation | Emitted data doesn't match schema | Fix emit data or schema |
Precision
Scheduled events fire within about a minute of the target time. This is intentional -- scheduled events are for business logic like "send a reminder tomorrow" or "expire this offer in 7 days" where the exact second doesn't matter.
Environment behavior
Scheduled events fire in the same environment they were created in. An event scheduled in staging fires in staging, and an event scheduled in prod fires in prod. This allows testing scheduled event logic in staging without affecting production.
Reset cancels pending timers in the selected environment and preserves timers elsewhere. It does not delete dead letters or timer history. Stop ordinary writers before reset when you need the environment to remain empty afterward.
Limits
| Limit | Value |
|---|---|
| Min delay | 5 minutes |
| Fire failures before dead-lettering | 10 |
Best practices
Use cancellation liberally. Always cancel if the triggering condition changes. It's cheaper to cancel than to handle no-op events.
Short delays in implications. Use scheduled events for delays over 5 minutes. For sub-minute coordination, use implications or sagas.
Monitor pending count. Too many scheduled events indicates a leak -- something that should cancel isn't.
All times are UTC. Convert in your application before scheduling.
See also
- Implications guide - Trigger scheduled events from implications
- Sagas guide - Complex workflows where race conditions must be explicitly resolved