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
impl Job
Sourcepub fn new(job_type: impl Into<String>, payload: Value) -> Job
pub fn new(job_type: impl Into<String>, payload: Value) -> Job
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");Sourcepub fn priority(self, priority: i32) -> Job
pub fn priority(self, priority: i32) -> Job
Sets job execution priority (higher numbers are leased first).
Sourcepub fn max_attempts(self, max_attempts: i32) -> Job
pub fn max_attempts(self, max_attempts: i32) -> Job
Sets maximum retry attempts before moving job to Dead-Letter Queue (DLQ).
Sourcepub fn payload_json(&self) -> &Value
pub fn payload_json(&self) -> &Value
Returns reference to job JSON payload.
Sourcepub fn payload_typed<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
pub fn payload_typed<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
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<'de> Deserialize<'de> for Job
impl<'de> Deserialize<'de> for Job
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Job, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Job, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<'a, R> FromRow<'a, R> for Jobwhere
R: Row,
&'a str: ColumnIndex<R>,
String: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
Option<Uuid>: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
Uuid: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
Value: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
DateTime<Utc>: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
i32: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
Option<DateTime<Utc>>: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
Option<String>: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
impl<'a, R> FromRow<'a, R> for Jobwhere
R: Row,
&'a str: ColumnIndex<R>,
String: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
Option<Uuid>: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
Uuid: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
Value: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
DateTime<Utc>: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
i32: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
Option<DateTime<Utc>>: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
Option<String>: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
Source§impl Serialize for Job
impl Serialize for Job
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more