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 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 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.