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 stopped(id: JobId, command: String, pid: u32, pgid: u32) -> Self
pub fn stopped(id: JobId, command: String, pid: u32, pgid: u32) -> Self
Create a stopped job (from Ctrl-Z on a foreground process).
Sourcepub fn output_file(&self) -> Option<&PathBuf>
pub fn output_file(&self) -> Option<&PathBuf>
Get the output file path (if available).
Sourcepub fn is_done(&mut self) -> bool
pub fn is_done(&mut self) -> bool
Check if the job has completed.
Stopped jobs are not considered done.
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.