1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//! 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:
//! - [`Supervisor`] starts and joins the worker, scheduler, and reaper loops
//! for a typical worker process
//! - [`catalog::JobCatalog`] is the preferred startup API for handler
//! registration, definition sync, and catalog-validated enqueue helpers
//! - [`registry::JobRegistry`] stores concrete handlers directly for advanced
//! setups that manage definitions separately
//! - [`config::JobsConfig`] centralizes 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](https://github.com/featherenvy/runledger/blob/master/runledger-runtime/examples/worker_binary.rs)
//! - [Enqueue one job](https://github.com/featherenvy/runledger/blob/master/runledger-postgres/examples/enqueue_job.rs)
//! - [Enqueue a workflow DAG](https://github.com/featherenvy/runledger/blob/master/runledger-postgres/examples/workflow_dag.rs)
//! - [Use an external workflow gate](https://github.com/featherenvy/runledger/blob/master/runledger-postgres/examples/external_gate.rs)
//! - [Create a scheduled job entrypoint](https://github.com/featherenvy/runledger/blob/master/runledger-postgres/examples/schedule_job.rs)
//!
//! # Prelude
//!
//! ```rust
//! 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
//!
//! ```rust,no_run
//! # async fn demo(
//! # pool: runledger_postgres::DbPool,
//! # ) -> std::result::Result<(), Box<dyn std::error::Error>> {
//! use std::time::Duration;
//!
//! use runledger_core::prelude::*;
//! use runledger_runtime::prelude::*;
//!
//! struct MyHandler;
//! # #[async_trait::async_trait]
//! # impl JobHandler for MyHandler {
//! # fn job_type(&self) -> JobType<'static> { JobType::new("jobs.example") }
//! # async fn execute(
//! # &self,
//! # _context: JobContext,
//! # _payload: serde_json::Value,
//! # ) -> std::result::Result<JobCompletion, JobFailure> { Ok(JobCompletion::success()) }
//! # }
//!
//! 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?;
//! # Ok(())
//! # }
//! ```
//!
//! 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.
pub use ;
pub use ;
pub use ;
/// Common `runledger-runtime` imports for worker-process integration.
///
/// This prelude avoids generic `Result` or `Error` aliases so it can be
/// glob-imported alongside the core and PostgreSQL preludes.
/// Reason a low-level runtime loop exited.
pub