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
impl Context
Sourcepub(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
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.
Sourcepub fn results(&self) -> ResultSink<'_>
pub fn results(&self) -> ResultSink<'_>
Get a ResultSink for pushing results back to the daemon.
Sourcepub fn progress(&self, pct: f64, message: &str) -> Result<()>
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.
Sourcepub fn emit_event(&self, event: Event) -> Result<()>
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.
Sourcepub fn warn(&self, message: &str) -> Result<()>
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.
Sourcepub fn mark_collected(&self, path: impl AsRef<Path>)
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.
Sourcepub(crate) fn close_result_channel(&self)
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.
Sourcepub(crate) fn claimed_paths(&self) -> HashSet<PathBuf>
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
impl Context
Sourcepub fn test_new(emitter: Arc<dyn TransportEmitter + Send + Sync>) -> Context
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.
Sourcepub fn test_new_with_tx(
emitter: Arc<dyn TransportEmitter + Send + Sync>,
tx: ResultSender,
) -> Context
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Context
impl !RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl !UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].