Skip to main content

Job

Struct Job 

Source
pub struct Job {
Show 17 fields pub dataset_id: String, pub replay_of_job_id: Option<Uuid>, pub id: Uuid, pub queue: String, pub job_type: String, pub payload: Value, pub run_at: DateTime<Utc>, pub status: String, pub priority: i32, pub max_attempts: i32, pub locked_at: Option<DateTime<Utc>>, pub locked_by: Option<String>, pub lock_expires_at: Option<DateTime<Utc>>, pub dlq_reason_code: Option<String>, pub dlq_at: Option<DateTime<Utc>>, pub created_at: DateTime<Utc>, pub updated_at: DateTime<Utc>,
}
Expand description

Primary job entity representing a unit of work stored in a storage backend.

§Examples

use azums_core::Job;

let job = Job::new("email_send", serde_json::json!({"to": "user@example.com"}))
    .queue("emails")
    .priority(10)
    .max_attempts(5);

assert_eq!(job.queue, "emails");
assert_eq!(job.priority, 10);
assert_eq!(job.max_attempts, 5);
assert_eq!(job.payload["to"], "user@example.com");

Fields§

§dataset_id: String§replay_of_job_id: Option<Uuid>§id: Uuid§queue: String§job_type: String§payload: Value§run_at: DateTime<Utc>§status: String§priority: i32§max_attempts: i32§locked_at: Option<DateTime<Utc>>§locked_by: Option<String>§lock_expires_at: Option<DateTime<Utc>>§dlq_reason_code: Option<String>§dlq_at: Option<DateTime<Utc>>§created_at: DateTime<Utc>§updated_at: DateTime<Utc>

Implementations§

Source§

impl Job

Source

pub fn new(job_type: impl Into<String>, payload: Value) -> Self

Creates a new Job with default queue "default", priority 0, and max attempts 25.

§Examples
use azums_core::Job;

let job = Job::new("greet", serde_json::json!({"name": "World"}));
assert_eq!(job.job_type, "greet");
assert_eq!(job.payload["name"], "World");
Source

pub fn queue(self, queue: impl Into<String>) -> Self

Sets target queue name for this job.

Source

pub fn priority(self, priority: i32) -> Self

Sets job execution priority (higher numbers are leased first).

Source

pub fn max_attempts(self, max_attempts: i32) -> Self

Sets maximum retry attempts before moving job to Dead-Letter Queue (DLQ).

Source

pub fn run_at(self, run_at: DateTime<Utc>) -> Self

Sets scheduled execution timestamp (run_at).

Source

pub fn payload_json(&self) -> &Value

Returns reference to job JSON payload.

Source

pub fn payload_typed<T: DeserializeOwned>(&self) -> Result<T, Error>

Deserializes the JSON payload into a concrete type T.

§Examples
use azums_core::{Job, Error};
use serde::Deserialize;

#[derive(Deserialize, Debug, PartialEq)]
struct EmailPayload {
    to: String,
}

let job = Job::new("email", serde_json::json!({"to": "a@b.com"}));
let payload: EmailPayload = job.payload_typed().unwrap();
assert_eq!(payload.to, "a@b.com");

Trait Implementations§

Source§

impl Clone for Job

Source§

fn clone(&self) -> Job

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Job

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Job

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Job> for NewJob

Source§

fn from(job: Job) -> Self

Converts to this type from the input type.
Source§

impl Serialize for Job

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.