Skip to main content

TaskHandler

Struct TaskHandler 

Source
pub struct TaskHandler { /* private fields */ }
Expand description

Task handler for managing multiple workers.

Implementations§

Source§

impl TaskHandler

Source

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

Source

pub fn builder(config: Configuration) -> TaskHandlerBuilder

Create a builder for more flexible configuration.

Source

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.

Source

pub fn add_workers( &mut self, workers: impl IntoIterator<Item = Arc<dyn Worker>>, )

Add multiple workers.

Source

pub fn add_event_listener(&self, listener: Arc<dyn TaskRunnerEventsListener>)

Register an event listener.

Source

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.

Source

pub fn metrics_collector(&self) -> Option<&Arc<MetricsCollector>>

Get the metrics collector.

Source

pub fn event_dispatcher(&self) -> &EventDispatcher

Get the event dispatcher.

Source

pub fn task_client(&self) -> TaskClient

Get a task client.

Source

pub fn metadata_client(&self) -> MetadataClient

Get a metadata client.

Source

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.

Source

pub fn schema_client(&self) -> SchemaClient

Get a schema client.

Source

pub async fn start(&mut self) -> Result<()>

Start all workers.

§Errors

Returns crate::error::ConductorError::Worker if no workers are registered.

Source

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.

Source

pub async fn stop(&mut self) -> Result<()>

Stop all workers gracefully.

This method:

  1. Signals all runners to stop polling
  2. Waits for in-flight tasks to complete (up to 30 seconds)
  3. 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).

Source

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.

Source

pub fn worker_count(&self) -> usize

Get the number of registered workers.

Source

pub fn is_running(&self) -> bool

Check if all workers are running.

Source

pub fn pause_worker(&self, task_type: &str)

Pause a specific worker by task type.

Source

pub fn resume_worker(&self, task_type: &str)

Resume a specific worker by task type.

Source

pub fn pause_all(&self)

Pause all workers.

Source

pub fn resume_all(&self)

Resume all workers.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more