pub struct Job {
pub id: JobId,
pub command: String,
/* private fields */
}Expand description
A background job.
Fields§
§id: JobIdJob ID.
command: StringCommand description.
Implementations§
Source§impl Job
impl Job
Sourcepub fn new(id: JobId, command: String, handle: JoinHandle<ExecResult>) -> Self
pub fn new(id: JobId, command: String, handle: JoinHandle<ExecResult>) -> Self
Create a new job from a task handle.
Sourcepub fn from_channel(
id: JobId,
command: String,
rx: Receiver<ExecResult>,
) -> Self
pub fn from_channel( id: JobId, command: String, rx: Receiver<ExecResult>, ) -> Self
Create a new job from a result channel.
Sourcepub fn with_streams(
id: JobId,
command: String,
rx: Receiver<ExecResult>,
stdout: Arc<BoundedStream>,
stderr: Arc<BoundedStream>,
) -> Self
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.
Sourcepub fn output_file(&self) -> Option<&PathBuf>
pub fn output_file(&self) -> Option<&PathBuf>
Get the output file path (if available).
Sourcepub fn status_string(&mut self) -> String
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
Sourcepub fn stdout_stream(&self) -> Option<&Arc<BoundedStream>>
pub fn stdout_stream(&self) -> Option<&Arc<BoundedStream>>
Get the stdout stream (if attached).
Sourcepub fn stderr_stream(&self) -> Option<&Arc<BoundedStream>>
pub fn stderr_stream(&self) -> Option<&Arc<BoundedStream>>
Get the stderr stream (if attached).
Sourcepub async fn wait(&mut self) -> ExecResult
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.
Sourcepub fn cleanup_files(&mut self)
pub fn cleanup_files(&mut self)
Remove any temp files associated with this job.
Sourcepub fn try_result(&self) -> Option<&ExecResult>
pub fn try_result(&self) -> Option<&ExecResult>
Get the result if completed, without waiting.
Auto Trait Implementations§
impl Freeze for Job
impl !RefUnwindSafe for Job
impl Send for Job
impl Sync for Job
impl Unpin for Job
impl !UnwindSafe for Job
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
Mutably borrows from an owned value. Read more