Expand description
Core durable-execution contracts shared by Runledger storage, runtime, and application crates.
Use this crate for the storage-agnostic pieces of the job system:
jobs::JobHandlerandjobs::JobHandlerRegistryfor handler contractsjobs::JobContext,jobs::JobProgress, andjobs::JobFailurefor execution-time state- workflow enqueue builders and validation helpers such as
jobs::WorkflowDagBuilder,jobs::WorkflowRunEnqueueBuilder, andjobs::validate_workflow_run_enqueue
Use workflow builders when work has dependencies, fan-out/fan-in, external gates, or workflow-level idempotency. A single direct job is appropriate only for one independent unit of retried work.
This crate does not provide persistence or worker loops. Pair it with
runledger-postgres for PostgreSQL-backed storage and runledger-runtime
for worker, scheduler, and reaper execution.
§Copy-Paste Examples
- Enqueue one job
- Enqueue a workflow DAG
- Use an external workflow gate
- Run a worker binary
- Create a scheduled job entrypoint
§Prelude
Import the common contracts with:
use runledger_core::prelude::*;The prelude intentionally exports contract types and builders, not storage or
runtime APIs. Pair it with runledger_postgres::prelude::* and
runledger_runtime::prelude::* in integration crates.
§Build A Job Handler
use runledger_core::prelude::*;
use serde_json::Value;
struct SendEmail;
#[async_trait]
impl JobHandler for SendEmail {
fn job_type(&self) -> JobType<'static> {
JobType::new("jobs.email.send")
}
async fn execute(&self, _context: JobContext, _payload: Value) -> Result<(), JobFailure> {
Ok(())
}
}§Build A Workflow DAG
use runledger_core::prelude::*;
let crawl_payload = serde_json::json!({"profile_id": "p_123"});
let classify_payload = serde_json::json!({"profile_id": "p_123"});
let metadata = serde_json::json!({"source": "api"});
let run = WorkflowDagBuilder::new("profiles.research", &metadata)
.job("crawl", "profiles.crawl", &crawl_payload)?
.job("classify", "profiles.classify", &classify_payload)?
.after_success("classify", ["crawl"])?
.build()?;