Expand description
Async runtime loops for executing Runledger jobs against a persistence backend.
Use this crate to wire the operational pieces around runledger-core
handlers and runledger-postgres storage:
Supervisorstarts and joins the worker, scheduler, and reaper loops for a typical worker processcatalog::JobCatalogis the preferred startup API for handler registration, definition sync, and catalog-validated enqueue helpersregistry::JobRegistrystores concrete handlers directly for advanced setups that manage definitions separatelyconfig::JobsConfigcentralizes poll, lease, and concurrency settings
A typical service builds a shared PostgreSQL pool, registers handlers in a
catalog::JobCatalog, syncs definitions during startup, and starts a
Supervisor with SupervisorBuilder::with_catalog. Worker processes
should call Supervisor::run_until_shutdown to observe task failures while
still applying a bounded shutdown deadline. Use
Supervisor::shutdown_with_timeout when shutdown is signaled externally, or
Supervisor::shutdown when the caller already has an external shutdown
budget or knows all loops will exit promptly.
The lower-level worker::run_worker_loop, scheduler::run_scheduler_loop,
and reaper::run_reaper_loop functions remain public for custom process
orchestration, but Supervisor is the preferred runtime facade.
§Copy-Paste Examples
- Run a worker binary
- Enqueue one job
- Enqueue a workflow DAG
- Use an external workflow gate
- Create a scheduled job entrypoint
§Prelude
use runledger_runtime::prelude::*;The runtime prelude exports the worker-process facade and configuration
types. Import runledger_core::prelude::* for handler contracts and
runledger_postgres::prelude::* for persistence APIs.
§Run A Worker Process
use std::time::Duration;
use runledger_core::prelude::*;
use runledger_runtime::prelude::*;
struct MyHandler;
let catalog = JobCatalog::new().job("jobs.example", MyHandler);
catalog.sync_definitions(&pool).await?;
let supervisor = Supervisor::builder(&pool, JobsConfig::from_env())?
.with_catalog(&catalog)
.build()?;
supervisor
.run_until_shutdown(std::future::pending::<()>(), Duration::from_secs(30))
.await?;Use Supervisor::run_until_shutdown for ordinary worker binaries so the
process observes internal runtime task failures while still applying a
bounded shutdown deadline. Use the lower-level loop functions only for custom
process orchestration.
Re-exports§
pub use error::Error;pub use error::ReaperError;pub use error::Result;pub use error::RuntimeError;pub use error::SchedulerError;pub use error::WorkerError;pub use supervisor::Supervisor;pub use supervisor::SupervisorBuilder;pub use supervisor::SupervisorShutdown;
Modules§
- catalog
- Catalog-backed startup API for keeping handlers, job definitions, schedules, and workflow steps aligned.
- config
- error
- prelude
- Common
runledger-runtimeimports for worker-process integration. - reaper
- registry
- scheduler
- supervisor
- worker
Enums§
- Runtime
Loop Exit - Reason a low-level runtime loop exited.