Skip to main content

Context

Struct Context 

Source
pub struct Context {
    inner: Arc<ContextInner>,
}
Expand description

The main handle plugins interact with during task execution.

Provides access to task metadata, result pushing, and progress reporting. Context is cheaply cloneable (it wraps an Arc) so you can share it with background threads.

Fields§

§inner: Arc<ContextInner>

Implementations§

Source§

impl Context

Source

pub(crate) fn new( task_id: i32, sample_path: PathBuf, config: HashMap<String, String>, emitter: Arc<dyn TransportEmitter + Send + Sync>, result_tx: Option<ResultSender>, stash: Option<Arc<ResultStash>>, ) -> Self

Create a new context with task data, a transport emitter, and an optional result channel.

Used by the runtime; downstream test code should use Context::test_new under the testkit feature.

Source

pub fn task(&self) -> TaskInfo<'_>

Get a read-only view of the current task’s metadata.

Source

pub fn results(&self) -> ResultSink<'_>

Get a ResultSink for pushing results back to the daemon.

Source

pub fn progress(&self, pct: f64, message: &str) -> Result<()>

Report execution progress (0.0 to 1.0) with a status message.

Progress updates are streamed to the daemon in real-time and can be shown in the UI. The progress value is clamped to [0.0, 1.0].

If a result channel is available, a PROGRESS-kind message is sent over it. Otherwise, just logs the progress.

§Panics

Uses blocking_send internally. Must be called from a blocking context (e.g. spawn_blocking), not from within an async task.

Source

pub fn emit_event(&self, event: Event) -> Result<()>

Send a transport-level event to the daemon.

Most plugins won’t need this - it’s an escape hatch for cases where you need to signal something outside the normal result flow.

Source

pub fn warn(&self, message: &str) -> Result<()>

Emit a warning via tracing at the WARN level.

For guest plugins, warnings are captured by the LogBus and streamed to the daemon. They appear in the log stream, not in the task report - use ResultSink::push for structured results.

Source

pub fn mark_collected(&self, path: impl AsRef<Path>)

Mark a file path as already handled so auto-collection skips it.

Call this when your plugin reads a file from the artifacts directory and sends its own processed version as a result. Without this, the auto-collector would send the raw file as a duplicate.

Source

pub(crate) fn close_result_channel(&self)

Close the result channel, preventing further pushes.

Called by the runtime after on_stop to signal end-of-task.

Source

pub(crate) fn claimed_paths(&self) -> HashSet<PathBuf>

Return a snapshot of all claimed file paths.

Used internally by auto-collection to determine which files have already been explicitly sent or marked.

Source§

impl Context

Source

pub fn test_new(emitter: Arc<dyn TransportEmitter + Send + Sync>) -> Context

Create a minimal test context with task ID 0, an empty sample path, and no result channel. Results pushed on this context will be dropped.

Source

pub fn test_new_with_tx( emitter: Arc<dyn TransportEmitter + Send + Sync>, tx: ResultSender, ) -> Context

Create a test context wired to an mpsc sender so you can inspect results pushed during the test.

Source

pub fn test_new_full( task_id: i32, sample_path: PathBuf, config: HashMap<String, String>, emitter: Arc<dyn TransportEmitter + Send + Sync>, result_tx: Option<ResultSender>, ) -> Context

Create a test context with explicit values for every field.

Trait Implementations§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Context

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

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

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

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.

§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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