Skip to main content

Module scheduler

Module scheduler 

Source
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:

FieldPositionsAccepted values
minute0*, */N, 0–59
hour1*, */N, 0–23

Only minute and hour fields are parsed (a two-field mini-cron). Second-level precision is not supported.

§Expression examples

ExpressionMeaning
* *Every minute
*/5 *Every 5 minutes
0 *At the top of every hour
0 9Every day at 09:00
30 6Every day at 06:30
*/15 8Every 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§

CronExpression
A parsed two-field mini-cron expression "MINUTE HOUR".
ScheduledPrompt
A prompt template paired with a cron schedule and target pipeline.
Scheduler
Tokio-based scheduler that fires prompt submissions on a cron-like interval.
SchedulerState
Thread-safe wrapper around a Scheduler for use as Axum State.