Skip to main content

Job

Struct Job 

Source
pub struct Job {
    pub id: JobId,
    pub command: String,
    /* private fields */
}
Expand description

A background job.

Fields§

§id: JobId

Job ID.

§command: String

Command description.

Implementations§

Source§

impl Job

Source

pub fn new(id: JobId, command: String, handle: JoinHandle<ExecResult>) -> Self

Create a new job from a task handle.

Source

pub fn from_channel( id: JobId, command: String, rx: Receiver<ExecResult>, ) -> Self

Create a new job from a result channel.

Source

pub fn with_streams( id: JobId, command: String, rx: Receiver<ExecResult>, stdout: Arc<BoundedStream>, stderr: Arc<BoundedStream>, ) -> Self

Create a new job with attached output streams.

The streams provide live access to job output via /v/jobs/{id}/stdout and /stderr.

Source

pub fn stopped(id: JobId, command: String, pid: u32, pgid: u32) -> Self

Create a stopped job (from Ctrl-Z on a foreground process).

Source

pub fn output_file(&self) -> Option<&PathBuf>

Get the output file path (if available).

Source

pub fn is_done(&mut self) -> bool

Check if the job has completed.

Stopped jobs are not considered done.

Source

pub fn status(&mut self) -> JobStatus

Get the job’s status.

Source

pub fn status_string(&mut self) -> String

Get the job’s status as a string suitable for /v/jobs/{id}/status.

Returns:

  • "running" if the job is still running
  • "done:0" if the job completed successfully
  • "failed:{code}" if the job failed with an exit code
Source

pub fn stdout_stream(&self) -> Option<&Arc<BoundedStream>>

Get the stdout stream (if attached).

Source

pub fn stderr_stream(&self) -> Option<&Arc<BoundedStream>>

Get the stderr stream (if attached).

Source

pub async fn wait(&mut self) -> ExecResult

Wait for the job to complete and return its result.

On completion, the job’s output is written to a temp file for later retrieval.

Source

pub fn cleanup_files(&mut self)

Remove any temp files associated with this job.

Source

pub fn try_result(&self) -> Option<&ExecResult>

Get the result if completed, without waiting.

Source

pub fn try_poll(&mut self) -> bool

Try to poll the result channel and update status.

This is a non-blocking check that updates self.result if the job has completed. Returns true if the job is now done.

Auto Trait Implementations§

§

impl Freeze for Job

§

impl !RefUnwindSafe for Job

§

impl Send for Job

§

impl Sync for Job

§

impl Unpin for Job

§

impl UnsafeUnpin for Job

§

impl !UnwindSafe for Job

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<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

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