Expand description
Cron-style scheduler for periodic LLM prompt submissions.
This module lets you register named prompt templates paired with a cron-like schedule expression. A background Tokio task wakes up at the right wall-clock times and submits the prompt through the pipeline’s standard input channel.
§Supported cron expressions
The parser supports a simplified subset of cron:
| Field | Positions | Accepted values |
|---|---|---|
| minute | 0 | *, */N, 0–59 |
| hour | 1 | *, */N, 0–23 |
Only minute and hour fields are parsed (a two-field mini-cron).
Second-level precision is not supported.
§Expression examples
| Expression | Meaning |
|---|---|
* * | Every minute |
*/5 * | Every 5 minutes |
0 * | At the top of every hour |
0 9 | Every day at 09:00 |
30 6 | Every day at 06:30 |
*/15 8 | Every 15 minutes during the 8 o’clock hour |
§Quick start
use std::sync::Arc;
use tokio::sync::mpsc;
use tokio_prompt_orchestrator::{PromptRequest, SessionId};
use tokio_prompt_orchestrator::scheduler::{Scheduler, ScheduledPrompt};
#[tokio::main]
async fn main() {
let (tx, mut rx) = mpsc::channel::<PromptRequest>(256);
let scheduler = Arc::new(Scheduler::new(tx));
let prompt = ScheduledPrompt::new("health-check", "*/5 *", "Are you operational?")
.expect("valid cron expression");
scheduler.add(prompt).await.expect("prompt registered");
let handle = scheduler.spawn();
// The scheduler runs until the handle is dropped or abort() is called.
handle.abort();
}§Web API integration
When the web-api feature is enabled, the SchedulerState type provides
a thread-safe wrapper suitable for use as Axum State.
Register routes with [scheduler_routes] to expose
POST /api/v1/schedule, GET /api/v1/schedule, and
DELETE /api/v1/schedule/:id.
Structs§
- Cron
Expression - A parsed two-field mini-cron expression
"MINUTE HOUR". - Scheduled
Prompt - A prompt template paired with a cron schedule and target pipeline.
- Scheduler
- Tokio-based scheduler that fires prompt submissions on a cron-like interval.
- Scheduler
State - Thread-safe wrapper around a
Schedulerfor use as AxumState.