System Architecture
The automation system is built on a layered architecture where user-facing “Objectives” are backed by technical “Routines”.- Objectives: High-level entities representing long-term goals or recurring checks (e.g., “Monitor server health”).
- Routines: The execution engine that handles triggers, delivery configuration, and quiet hours.
- Cron: The specific implementation of schedule-based triggers within the routine system.
Entity Relationship Diagram
The following diagram shows how high-level concepts map to internal code structures. “Natural Language Space to Code Entity Space” Sources: crates/palyra-daemon/src/transport/http/handlers/console/routines.rs#18-25, apps/web/src/console/sections/OverviewSection.tsx#64-78Objectives
Objectives represent durable stateful goals. They are managed via thepalyra objectives command group crates/palyra-cli/src/args/mod.rs#138.
Objective Types (ObjectiveKindArg)
Defined in crates/palyra-cli/src/args/objectives.rs#150-155:
- Objective: A standard goal-oriented task.
- Heartbeat: A recurring check-in or status monitor.
- Standing Order: Persistent instructions applied to specific contexts.
- Program: A complex, multi-step automated workflow.
Objective Lifecycle Actions
Objectives transition through several states (ObjectiveStateArg): Draft, Active, Paused, Cancelled, and Archived crates/palyra-cli/src/args/objectives.rs#170-176.
Key lifecycle commands implemented in run_objectives_async:
- Fire: Manually trigger an objective run immediately crates/palyra-cli/src/commands/objectives.rs#117-121.
- Pause: Suspend scheduled runs crates/palyra-cli/src/commands/objectives.rs#122-126.
- Resume: Re-enable a paused objective crates/palyra-cli/src/commands/objectives.rs#127-131.
Routines & Scheduling
Routines are the unified automation surface for schedules and event triggers crates/palyra-cli/src/args/mod.rs#139.Schedule Configuration
Routines support multiple schedule types defined inObjectiveScheduleTypeArg crates/palyra-cli/src/args/objectives.rs#212-217:
- Cron: Standard crontab expressions.
- Every: Interval-based execution (e.g., every 5 minutes).
- At: One-time execution at a specific timestamp.
Routine Features
| Feature | Implementation | Description |
|---|---|---|
| Natural Language | natural_language_schedule | Parses phrases like “every Friday at noon” into cron expressions crates/palyra-daemon/src/transport/http/handlers/console/routines.rs#72. |
| Quiet Hours | RoutineQuietHours | Prevents execution during specific time windows (e.g., 10 PM to 6 AM) crates/palyra-daemon/src/transport/http/handlers/console/routines.rs#96-100. |
| Approval Mode | RoutineApprovalMode | Defines if a run requires human intervention (None, Required, Always) crates/palyra-daemon/src/transport/http/handlers/console/routines.rs#104. |
| Delivery | RoutineDeliveryConfig | Configures where the output is sent (e.g., a specific Discord channel) crates/palyra-daemon/src/transport/http/handlers/console/routines.rs#92-94. |
Cron Commands
Thepalyra cron command group provides a schedule-only interface that interacts with the routines compatibility layer crates/palyra-cli/tests/help_snapshots/root-help-unix.txt#17.
Data Flow: Schedule to Execution
The following diagram traces a scheduled task from configuration to the daemon’s internalCronJobRecord.
“Cron Execution Flow”
Sources: crates/palyra-daemon/src/transport/http/handlers/console/routines.rs#154-215, crates/palyra-daemon/src/transport/http/handlers/console/routines.rs#9-25
Key Parameters
- Concurrency Policy: Controls overlapping runs (
Allow,Forbid,Replace) crates/palyra-daemon/src/transport/http/handlers/console/routines.rs#82. - Misfire Policy: Determines behavior if the daemon was offline during a scheduled time crates/palyra-daemon/src/transport/http/handlers/console/routines.rs#88.
- Jitter: Adds random delay to prevent “thundering herd” issues crates/palyra-daemon/src/transport/http/handlers/console/routines.rs#90.
Implementation Details
Console Handlers
The logic for managing these entities resides incrates/palyra-daemon/src/transport/http/handlers/console/routines.rs.
console_routines_list_handler: Filters and paginates routines based ontrigger_kind,enabledstatus, andtemplate_idcrates/palyra-daemon/src/transport/http/handlers/console/routines.rs#154-215.ConsoleRoutineUpsertRequest: The comprehensive struct used to create or update routines, mapping all schedule and delivery parameters crates/palyra-daemon/src/transport/http/handlers/console/routines.rs#53-107.
Web Console Integration
The Web UI provides specialized sections for these systems:- OverviewSection: Displays active objectives, heartbeats, and attention items apps/web/src/console/sections/OverviewSection.tsx#100-155.
- CronSection: Manages schedule-based routines and provides a “Schedule Preview” using the
phraseandtimezonefields apps/web/src/console/sections/CronSection.tsx#64-133.