pub struct TaskHandler { /* private fields */ }Expand description
Task handler for managing multiple workers.
Implementations§
Source§impl TaskHandler
impl TaskHandler
Sourcepub fn new(config: Configuration) -> Result<Self>
pub fn new(config: Configuration) -> Result<Self>
Create a new task handler with the given configuration.
§Errors
Returns crate::error::ConductorError::Http if the underlying reqwest client fails to build (see ApiClient::new).
Sourcepub fn builder(config: Configuration) -> TaskHandlerBuilder
pub fn builder(config: Configuration) -> TaskHandlerBuilder
Create a builder for more flexible configuration.
Sourcepub fn add_worker(&mut self, worker: impl Worker + 'static)
pub fn add_worker(&mut self, worker: impl Worker + 'static)
Add a worker to the handler.
Registration is always explicit – there is no scan-a-package auto-discovery here.
Rust’s callers already write out every TaskDef/AgentDef/ToolDef by hand at a
well-typed call site, so scanning for them would only add indirection, not remove real
boilerplate. A crate-level inventory dependency was carried for a while in anticipation
of a #[worker]-style attribute macro doing inventory::submit!-based collection
instead, but was removed unused: besides never having a caller, that approach has a real
sharp edge inventory itself documents – registrations only get linked in if the
registering crate is a direct dependency of the final binary, which link-time
dead-code elimination can silently defeat depending on build settings.
add_worker/add_workers (and TaskHandlerBuilder::worker/
TaskHandlerBuilder::workers) staying explicit sidesteps that class of bug entirely.
Sourcepub fn add_workers(
&mut self,
workers: impl IntoIterator<Item = Arc<dyn Worker>>,
)
pub fn add_workers( &mut self, workers: impl IntoIterator<Item = Arc<dyn Worker>>, )
Add multiple workers.
Sourcepub fn add_event_listener(&self, listener: Arc<dyn TaskRunnerEventsListener>)
pub fn add_event_listener(&self, listener: Arc<dyn TaskRunnerEventsListener>)
Register an event listener.
Sourcepub fn enable_metrics(&mut self, settings: MetricsSettings)
pub fn enable_metrics(&mut self, settings: MetricsSettings)
Enable metrics collection and (optionally) the HTTP scrape endpoint.
Creates a MetricsCollector with the given settings and wires it
as both the TaskRunnerEventsListener (for task/workflow counters
and histograms) and the
HttpMetricsObserver (for
http_api_client_request_seconds).
Must be called before start. Clients vended
after this call (via conductor_client,
task_client, etc.) will share the observer.
Sourcepub fn metrics_collector(&self) -> Option<&Arc<MetricsCollector>>
pub fn metrics_collector(&self) -> Option<&Arc<MetricsCollector>>
Get the metrics collector.
Sourcepub fn event_dispatcher(&self) -> &EventDispatcher
pub fn event_dispatcher(&self) -> &EventDispatcher
Get the event dispatcher.
Sourcepub fn task_client(&self) -> TaskClient
pub fn task_client(&self) -> TaskClient
Get a task client.
Sourcepub fn metadata_client(&self) -> MetadataClient
pub fn metadata_client(&self) -> MetadataClient
Get a metadata client.
Sourcepub fn conductor_client(&self) -> ConductorClient
pub fn conductor_client(&self) -> ConductorClient
Get the Conductor client wired to this handler’s event dispatcher.
Sharing the dispatcher means WorkflowStarted /
WorkflowStartFailure events emitted by the returned client’s
WorkflowClient flow into the same MetricsCollector that
enable_metrics installed.
Sourcepub fn schema_client(&self) -> SchemaClient
pub fn schema_client(&self) -> SchemaClient
Get a schema client.
Sourcepub async fn start(&mut self) -> Result<()>
pub async fn start(&mut self) -> Result<()>
Start all workers.
§Errors
Returns crate::error::ConductorError::Worker if no workers are registered.
Sourcepub async fn verify_workers_started(&self, timeout: Duration) -> Result<()>
pub async fn verify_workers_started(&self, timeout: Duration) -> Result<()>
Verify that every registered worker’s polling task actually started and completed at
least one real poll attempt against the server, within timeout. Call this right after
TaskHandler::start.
This crate’s workers are tokio::spawned futures in the same process, where spawning
itself essentially never fails silently – so the real risk isn’t “did the task get
scheduled,” it’s “did this worker’s task actually reach and complete its first poll,”
which catches an early panic during setup (before or shortly into TaskRunner::run)
or a spawned task that’s starved and never reaches the network call.
TaskRunner::poll_attempt_count is the signal used to tell that apart from
TaskRunner::is_running merely being true, which happens before the first poll is
even attempted.
No-op (returns Ok(()) immediately) if TaskHandler::start hasn’t been called yet, or
registered no workers – there’s nothing to verify.
§Errors
Returns crate::error::ConductorError::Worker naming every task type that either
exited before its first poll (its spawned task ended, e.g. via an early panic) or simply
hadn’t completed one within timeout.
Sourcepub async fn stop(&mut self) -> Result<()>
pub async fn stop(&mut self) -> Result<()>
Stop all workers gracefully.
This method:
- Signals all runners to stop polling
- Waits for in-flight tasks to complete (up to 30 seconds)
- Stops the metrics server
§Errors
Currently always returns Ok(()); the Result is reserved for future shutdown failures (e.g. a worker task panic is logged, not propagated).
Sourcepub async fn join(&mut self) -> Result<()>
pub async fn join(&mut self) -> Result<()>
Wait for all workers to complete.
§Errors
Currently always returns Ok(()); a worker task panic is logged, not propagated.
Sourcepub fn worker_count(&self) -> usize
pub fn worker_count(&self) -> usize
Get the number of registered workers.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if all workers are running.
Sourcepub fn pause_worker(&self, task_type: &str)
pub fn pause_worker(&self, task_type: &str)
Pause a specific worker by task type.
Sourcepub fn resume_worker(&self, task_type: &str)
pub fn resume_worker(&self, task_type: &str)
Resume a specific worker by task type.
Sourcepub fn resume_all(&self)
pub fn resume_all(&self)
Resume all workers.