pub struct WorkerBuilder { /* private fields */ }Expand description
Builder for configuring and creating a Worker.
§Examples
use std::sync::Arc;
use std::time::Duration;
use ironflow_worker::WorkerBuilder;
use ironflow_core::providers::claude::ClaudeCodeProvider;
let worker = WorkerBuilder::new("http://localhost:3000", "my-token")
.provider(Arc::new(ClaudeCodeProvider::new()))
.concurrency(4)
.poll_interval(Duration::from_secs(2))
.run_timeout(Duration::from_secs(600))
.max_consecutive_panics(5)
.build()?;
worker.run().await?;Implementations§
Source§impl WorkerBuilder
impl WorkerBuilder
Sourcepub fn new(api_url: &str, worker_token: &str) -> Self
pub fn new(api_url: &str, worker_token: &str) -> Self
Create a new builder targeting the given API server.
Sourcepub fn provider(self, provider: Arc<dyn AgentProvider>) -> Self
pub fn provider(self, provider: Arc<dyn AgentProvider>) -> Self
Set the agent provider for AI operations.
Sourcepub fn decision_provider(self, provider: Arc<dyn DecisionProvider>) -> Self
pub fn decision_provider(self, provider: Arc<dyn DecisionProvider>) -> Self
Set the DecisionProvider backend for ctx.decision(...) steps.
Every run executed by this worker gets it, like
Engine::with_decision_provider. Optional: without it, a workflow that
reaches a decision step fails with
EngineError::NoDecisionProvider.
A decision step already completed in the store is replayed without
calling the provider again.
§Examples
use std::sync::Arc;
use ironflow_core::providers::claude::ClaudeCodeProvider;
use ironflow_core::providers::record_replay_decision::RecordReplayDecisionProvider;
use ironflow_worker::WorkerBuilder;
let worker = WorkerBuilder::new("http://localhost:3000", "token")
.provider(Arc::new(ClaudeCodeProvider::new()))
.decision_provider(Arc::new(RecordReplayDecisionProvider::replay("tests/fixtures")))
.build()?;Sourcepub fn register(self, handler: impl WorkflowHandler + 'static) -> Self
pub fn register(self, handler: impl WorkflowHandler + 'static) -> Self
Register a workflow handler.
Sourcepub fn concurrency(self, n: usize) -> Self
pub fn concurrency(self, n: usize) -> Self
Set the maximum number of concurrent workflow executions.
Sourcepub fn poll_interval(self, interval: Duration) -> Self
pub fn poll_interval(self, interval: Duration) -> Self
Set the interval between polls for new runs.
Sourcepub fn run_timeout(self, timeout: Duration) -> Self
pub fn run_timeout(self, timeout: Duration) -> Self
Set the maximum execution time per run.
If a run exceeds this duration, it is cancelled and marked as Failed
with a timeout error. Defaults to 30 minutes.
§Examples
use std::time::Duration;
use ironflow_worker::WorkerBuilder;
let builder = WorkerBuilder::new("http://localhost:3000", "token")
.run_timeout(Duration::from_secs(600));Sourcepub fn max_consecutive_panics(self, n: u32) -> Self
pub fn max_consecutive_panics(self, n: u32) -> Self
Set the maximum number of consecutive panics per workflow before the worker stops picking runs for that workflow (poison pill guard).
When a workflow panics max_consecutive_panics times in a row without
a single success, the worker skips it for a cooldown period (see
panic_cooldown). Defaults to 3.
§Examples
use ironflow_worker::WorkerBuilder;
let builder = WorkerBuilder::new("http://localhost:3000", "token")
.max_consecutive_panics(5);Sourcepub fn panic_cooldown(self, cooldown: Duration) -> Self
pub fn panic_cooldown(self, cooldown: Duration) -> Self
Set the cooldown duration after a workflow is flagged as a poison pill.
After max_consecutive_panics is reached, runs for that workflow are
skipped until this duration elapses. Defaults to 5 minutes.
§Examples
use std::time::Duration;
use ironflow_worker::WorkerBuilder;
let builder = WorkerBuilder::new("http://localhost:3000", "token")
.panic_cooldown(Duration::from_secs(600));Sourcepub fn worker_id(self, worker_id: &str) -> Self
pub fn worker_id(self, worker_id: &str) -> Self
Set the identifier this worker uses to claim runs.
Defaults to worker-<uuid>, regenerated at every start so two processes
never share an identity. Override it only if you have a stable, unique
name per process.
§Examples
use ironflow_worker::WorkerBuilder;
let builder = WorkerBuilder::new("http://localhost:3000", "token")
.worker_id("worker-eu-west-1a");Sourcepub fn lease_ttl(self, ttl: Duration) -> Self
pub fn lease_ttl(self, ttl: Duration) -> Self
Set how long a lease stays valid without a refresh.
Once it expires, the API reaper requeues the run for another worker.
Keep it at a few times lease_refresh_interval
so a transient network blip does not hand the run over. Defaults to 90 s.
§Examples
use std::time::Duration;
use ironflow_worker::WorkerBuilder;
let builder = WorkerBuilder::new("http://localhost:3000", "token")
.lease_ttl(Duration::from_secs(120));Sourcepub fn lease_refresh_interval(self, interval: Duration) -> Self
pub fn lease_refresh_interval(self, interval: Duration) -> Self
Sourcepub fn build(self) -> Result<Worker, WorkerError>
pub fn build(self) -> Result<Worker, WorkerError>
Build the worker.
§Errors
Returns WorkerError::Internal if no provider has been set.
Returns WorkerError::Engine if a handler registration fails.