Skip to main content

Crate cronoq

Crate cronoq 

Source
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 Low work overtakes fresh Normal work, but never High or Critical work.
  • 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§

AutoscaleConfig
Engine types re-exported for convenience. Queue-pressure autoscaling parameters (see SPEC §10).
BlockingHandle
Blocking task handle.
BlockingScheduler
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 Skipped as soon as one edge can no longer be satisfied.
ExternalScaler
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.
GroupSnapshot
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.
MemoryStore
No persistence.
Pool
A worker pool: engine configuration plus its executor and scaler.
PoolConfig
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.
PoolSnapshot
Engine types re-exported for convenience. State and windowed quality metrics of one pool.
PriorityConfig
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.
RecoveredTask
Engine types re-exported for convenience. A non-terminal task restored from durable storage.
RecoveredTerminal
Engine types re-exported for convenience. A recently finished task restored into the retention table (for late dependents).
Recurring
A recurring (cron) schedule.
RecurringInfo
Engine types re-exported for convenience. A recurring schedule, as listed by Core::list_recurring.
RecurringSpec
Engine types re-exported for convenience. A cron schedule that submits a fixed-start task from template at each occurrence.
ResourceConfig
Engine types re-exported for convenience. A named resource tasks can require (concurrency or rate limit), shared across pools.
RetryPolicy
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.
SlotScaler
In-process concurrency slots: capacity follows the request immediately.
Snapshot
Engine types re-exported for convenience. Engine-wide snapshot returned by Core::snapshot.
StatusEvent
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 TaskSpec and resolves times at submission.
TaskContext
Information and controls for a running attempt.
TaskHandle
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).
TaskRecord
A task as a durable store last recorded it, for lookups after it left the engine.
TaskSpec
Engine types re-exported for convenience. Everything the engine needs to schedule one task.
TaskSummary
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.
TimeBase
Wall-clock anchor of engine time, for converting persisted timestamps: unix_nanos = unix_nanos_at_zero + engine_nanos.
UrgencyConfig
Engine types re-exported for convenience. Deadline urgency curve (monotonically increasing as slack shrinks).

Enums§

EdgeCond
Engine types re-exported for convenience. When a dependency edge is satisfied by its parent’s terminal status.
Error
Scheduler-level error.
MissPolicy
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).
OverflowPolicy
Engine types re-exported for convenience. Behaviour when a submission would exceed queue bounds.
OverlapPolicy
Engine types re-exported for convenience. Overlap behaviour for recurring schedules.
Priority
Engine types re-exported for convenience. Priority class. Lower discriminant = more important.
ResourceKind
Engine types re-exported for convenience. Kind of a shared resource.
ScaleError
Failure reported by a Scaler.
StoreError
Failure reported by a Store.
SubmitError
Engine types re-exported for convenience. Why a submission was rejected.
TaskError
Error returned by an executor for one attempt.
TaskFailure
Why a TaskHandle did not produce an output.
TaskRef
Engine types re-exported for convenience. Reference to another task, used for dependencies and cancellation.
TaskStatus
Engine types re-exported for convenience. Lifecycle status of a task.
UnknownDependency
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.
StoreQueries
Lookups and housekeeping a server needs from a durable store, beyond what the scheduler itself uses through Store.

Type Aliases§

BoxFuture
A boxed, Send future (what Executor::execute returns).
Labels
Engine types re-exported for convenience. Sorted (name, value) labels of a worker group.