Expand description
§cronoq
An elastic, priority-aware task scheduler for Rust (and Python, and over gRPC).
- Priorities with aging: four classes, FIFO within a class, and bounded aging; by default
long-waiting
Lowwork overtakes freshNormalwork, but neverHighorCriticalwork. - Deadlines: urgency rises as a task’s latest start time approaches.
- Fixed starts and cron: capacity is reserved and a worker is held ahead of time.
- DAGs: dependencies with success/failure/completion conditions.
- Reliability: leases, timeouts, retries with backoff, dead-lettering, cancellation.
- Resources: semaphores and token buckets shared across pools (e.g. API rate limits).
- Elasticity: queue-pressure autoscaling per pool through pluggable scalers.
- Observability: OpenTelemetry metrics and trace propagation; windowed quality metrics.
use std::time::Duration;
use cronoq::{Pool, Priority, Scheduler, Task, TaskError};
let sched = Scheduler::<String, usize>::builder()
.pool(Pool::new("default").workers(1, 2, 8).executor_fn(|_ctx, text: std::sync::Arc<String>| async move {
Ok::<_, TaskError>(text.len())
}))
.build()
.await?;
let h = sched.submit(Task::new("hello".to_string()).priority(Priority::High).deadline_in(Duration::from_secs(5))).await?;
assert_eq!(*h.await?, 5);
sched.shutdown(Duration::from_secs(5)).await?;Re-exports§
pub use cronoq_core as core;
Structs§
- Autoscale
Config - Engine types re-exported for convenience. Queue-pressure autoscaling parameters (see SPEC §10).
- Blocking
Handle - Blocking task handle.
- Blocking
Scheduler - A scheduler that owns its own tokio runtime and exposes blocking methods.
- Bounds
- Engine types re-exported for convenience. Maximum number of not-yet-running tasks.
- Builder
- Configures and starts a
Scheduler. - Clock
- Engine clock: Unix nanoseconds, advanced by tokio’s monotonic clock.
- Dep
- Engine types re-exported for convenience.
A dependency on another task. The dependent becomes eligible once every edge is satisfied
and ends as
Skippedas soon as one edge can no longer be satisfied. - External
Scaler - Capacity is managed elsewhere (e.g. KEDA/HPA reading the desired-workers metric, or
remote workers registering); report it with
Scheduler::set_capacity. - Fairness
- Engine types re-exported for convenience.
Weighted fair sharing of a pool between tenants (
TaskSpec::tenant). - FnExecutor
- Executor from an async closure.
- Group
Snapshot - Engine types re-exported for convenience. Capacity of the workers of a pool that share one label set.
- LeaseId
- Engine types re-exported for convenience. Identifies one dispatch (attempt) of a task.
- Memory
Store - No persistence.
- Pool
- A worker pool: engine configuration plus its executor and scaler.
- Pool
Config - Engine types re-exported for convenience. A worker pool: capacity limits, scaling, retries, queue bounds and fixed-start behaviour.
- PoolId
- Engine types re-exported for convenience. Index of a pool in the engine configuration.
- Pool
Snapshot - Engine types re-exported for convenience. State and windowed quality metrics of one pool.
- Priority
Config - Engine types re-exported for convenience.
Per-class score parameters:
base + min(aging_rate * wait, age_cap) + urgency. - Recovered
- Engine types re-exported for convenience.
Engine state restored from durable storage, passed to
Core::recover. - Recovered
Task - Engine types re-exported for convenience. A non-terminal task restored from durable storage.
- Recovered
Terminal - Engine types re-exported for convenience. A recently finished task restored into the retention table (for late dependents).
- Recurring
- A recurring (cron) schedule.
- Recurring
Info - Engine types re-exported for convenience.
A recurring schedule, as listed by
Core::list_recurring. - Recurring
Spec - Engine types re-exported for convenience.
A cron schedule that submits a fixed-start task from
templateat each occurrence. - Resource
Config - Engine types re-exported for convenience. A named resource tasks can require (concurrency or rate limit), shared across pools.
- Retry
Policy - Engine types re-exported for convenience. Retry behaviour for retryable failures.
- Scheduler
- Handle to a running scheduler. Cheap to clone; all methods are thread-safe.
- Slot
Scaler - In-process concurrency slots: capacity follows the request immediately.
- Snapshot
- Engine types re-exported for convenience.
Engine-wide snapshot returned by
Core::snapshot. - Status
Event - Engine types re-exported for convenience. Status transition event.
- Submitted
- Engine types re-exported for convenience. Result of an accepted submission.
- Task
- A task to submit. Wraps
TaskSpecand resolves times at submission. - Task
Context - Information and controls for a running attempt.
- Task
Handle - Resolves with the task’s output once it reaches a terminal status.
- TaskId
- Engine types re-exported for convenience. Engine-assigned task identifier (monotonic; the high 16 bits carry the leader epoch).
- Task
Record - A task as a durable store last recorded it, for lookups after it left the engine.
- Task
Spec - Engine types re-exported for convenience. Everything the engine needs to schedule one task.
- Task
Summary - Engine types re-exported for convenience.
A live task, as listed by
Core::list_tasks. - Time
- Engine types re-exported for convenience. Engine time: nanoseconds since the engine epoch.
- Time
Base - Wall-clock anchor of engine time, for converting persisted timestamps:
unix_nanos = unix_nanos_at_zero + engine_nanos. - Urgency
Config - Engine types re-exported for convenience. Deadline urgency curve (monotonically increasing as slack shrinks).
Enums§
- Edge
Cond - Engine types re-exported for convenience. When a dependency edge is satisfied by its parent’s terminal status.
- Error
- Scheduler-level error.
- Miss
Policy - Engine types re-exported for convenience. What to do when a fixed-start task could not start within its tolerance.
- Mutation
- Engine types re-exported for convenience.
Durable state change (emitted only with
CoreConfig::persist). - Overflow
Policy - Engine types re-exported for convenience. Behaviour when a submission would exceed queue bounds.
- Overlap
Policy - Engine types re-exported for convenience. Overlap behaviour for recurring schedules.
- Priority
- Engine types re-exported for convenience. Priority class. Lower discriminant = more important.
- Resource
Kind - Engine types re-exported for convenience. Kind of a shared resource.
- Scale
Error - Failure reported by a
Scaler. - Store
Error - Failure reported by a
Store. - Submit
Error - Engine types re-exported for convenience. Why a submission was rejected.
- Task
Error - Error returned by an executor for one attempt.
- Task
Failure - Why a
TaskHandledid not produce an output. - TaskRef
- Engine types re-exported for convenience. Reference to another task, used for dependencies and cancellation.
- Task
Status - Engine types re-exported for convenience. Lifecycle status of a task.
- Unknown
Dependency - Engine types re-exported for convenience. How to treat a dependency on a key the engine has never seen.
- When
- A point in time, relative to submission or absolute.
Traits§
- Executor
- Runs one attempt of a task.
- Scaler
- Carries out capacity changes requested by the autoscaler.
- Store
- Persistence backend. The engine is the system of record while running; the store is a write-ahead log of its state transitions, read back on startup or failover.
- Store
Queries - Lookups and housekeeping a server needs from a durable store, beyond what the scheduler
itself uses through
Store.
Type Aliases§
- BoxFuture
- A boxed,
Sendfuture (whatExecutor::executereturns). - Labels
- Engine types re-exported for convenience.
Sorted
(name, value)labels of a worker group.