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) -> Self
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");Sourcepub fn priority(self, priority: i32) -> Self
pub fn priority(self, priority: i32) -> Self
Sets job execution priority (higher numbers are leased first).
Sourcepub fn max_attempts(self, max_attempts: i32) -> Self
pub fn max_attempts(self, max_attempts: i32) -> Self
Sets maximum retry attempts before moving job to Dead-Letter Queue (DLQ).
Sourcepub fn run_at(self, run_at: DateTime<Utc>) -> Self
pub fn run_at(self, run_at: DateTime<Utc>) -> Self
Sets scheduled execution timestamp (run_at).
Sourcepub fn payload_json(&self) -> &Value
pub fn payload_json(&self) -> &Value
Returns reference to job JSON payload.
Sourcepub fn payload_typed<T: DeserializeOwned>(&self) -> Result<T, Error>
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<'de> Deserialize<'de> for Job
impl<'de> Deserialize<'de> for Job
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. 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