Job

Struct Job 

pub struct Job {
    info: JobInfo,
    mqtt: MqttClient,
    accepted: Option<OwnedSubscriber>,
    rejected: Option<OwnedSubscriber>,
}
Expand description

The Job struct represents a job execution and provides methods for updating it’s status.

Fields§

§info: JobInfo§mqtt: MqttClient§accepted: Option<OwnedSubscriber>§rejected: Option<OwnedSubscriber>

Implementations§

§

impl Job

const fn new(info: JobInfo, mqtt: MqttClient) -> Self

Creates a new Job instance with the given job information and MQTT client.

pub async fn update(&mut self, status: JobStatus) -> Result<(), Error>

Updates the status of the job to the specified status.

This function publishes a message to the $aws/things/{thing_name}/jobs/{job_id}/update topic to update the job execution status. It then waits for a response on the update_accepted and update_rejected topics, and returns an error if the request is rejected.

§Arguments
  • status - The new job status.
§Returns

A Result indicating the success or failure of the operation.

§Errors

This function may return the following errors:

  • Error::JobIdMissing - If the job ID is missing.
  • Error::JobVersion - If the job version is missing.
  • Error::UpdateJobRequestRejected - If the job update request is rejected.

pub async fn update_with_details( &mut self, status: JobStatus, details: HashMap<String, String>, ) -> Result<(), Error>

Updates the job with the specified status and additional details.

This function publishes a message to the $aws/things/{thing_name}/jobs/{job_id}/update topic to update the job execution status and details. It then waits for a response on the update_accepted and update_rejected topics, and returns an error if the request is rejected.

§Arguments
  • status - The new job status.
  • details - A map of additional details to include in the update.
§Returns

A Result indicating the success or failure of the operation.

§Errors

This function may return the following errors:

  • Error::JobIdMissing - If the job ID is missing.
  • Error::JobVersion - If the job version is missing.
  • Error::UpdateJobRequestRejected - If the job update request is rejected.

async fn update_internal( &mut self, update_req: UpdateJobExecutionReq, ) -> Result<(), Error>

pub fn id(&self) -> Option<&str>

Returns the ID of the job, if it exists.

This method returns an Option<&str> that contains the job ID if it is available, or None if the job ID is not set.

pub const fn status(&self) -> Option<&JobStatus>

Returns the current status of the job, if available.

pub const fn version(&self) -> Option<i32>

Returns the version of the job, if available.

pub const fn execution_number(&self) -> Option<i64>

Returns the execution number of the job, if available.

The execution number represents the number of times this job has been executed. It can be useful for tracking the progress or status of a job.

pub const fn details(&self) -> Option<&HashMap<String, String>>

Returns a reference to the details map associated with the job, if it exists.

The details map is a collection of key-value pairs that provide additional information about the job.

pub fn document(&self) -> Option<Value>

Returns a clone of the document associated with the job, if any.

pub const fn queued_at(&self) -> Option<DateTime<Utc>>

Returns the time when the job was queued, if available.

pub const fn started_at(&self) -> Option<DateTime<Utc>>

Returns the time when the job was started, if available.

pub const fn last_updated_at(&self) -> Option<DateTime<Utc>>

Returns the last time the job was updated.

Trait Implementations§

§

impl Debug for Job

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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

§

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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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