pub struct Job {Show 21 fields
pub dataset_id: String,
pub replay_of_job_id: Option<Uuid>,
pub idempotency_key: Option<String>,
pub id: Uuid,
pub queue: String,
pub job_type: String,
pub payload: Value,
pub run_at: DateTime<Utc>,
pub deadline_at: Option<DateTime<Utc>>,
pub timeout_seconds: Option<i64>,
pub recurring_interval_seconds: Option<i64>,
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>§idempotency_key: Option<String>§id: Uuid§queue: String§job_type: String§payload: Value§run_at: DateTime<Utc>§deadline_at: Option<DateTime<Utc>>§timeout_seconds: Option<i64>§recurring_interval_seconds: Option<i64>§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 idempotency_key(self, idempotency_key: impl Into<String>) -> Job
pub fn idempotency_key(self, idempotency_key: impl Into<String>) -> Job
Sets an application-provided enqueue idempotency key.
Backends that support idempotent enqueue return the existing logical job ID when another enqueue uses the same key.
Sourcepub fn deadline_at(self, deadline_at: DateTime<Utc>) -> Job
pub fn deadline_at(self, deadline_at: DateTime<Utc>) -> Job
Sets the latest timestamp at which this job may start execution.
If the backend clock is already past this value when workers try to lease the job, Azums
moves the job to DLQ with DEADLINE_EXCEEDED instead of executing it late.
Sourcepub fn timeout_seconds(self, timeout_seconds: i64) -> Job
pub fn timeout_seconds(self, timeout_seconds: i64) -> Job
Sets a per-attempt handler timeout in seconds.
Worker runtimes that execute handlers enforce this as a handler execution timeout and route timeout failures through normal retry/DLQ classification.
Sourcepub fn recurring_interval_seconds(self, interval_seconds: i64) -> Job
pub fn recurring_interval_seconds(self, interval_seconds: i64) -> Job
Sets fixed-interval recurring execution in seconds.
After a successful occurrence, Azums enqueues the next occurrence as a new logical job with
run_at = previous_run_at + recurring_interval_seconds.
Sourcepub fn payload_json(&self) -> &Value
pub fn payload_json(&self) -> &Value
Returns reference to job JSON payload.
Sourcepub fn lifecycle_state_at(
&self,
now: DateTime<Utc>,
failed_attempts: usize,
) -> Result<JobLifecycleState, Error>
pub fn lifecycle_state_at( &self, now: DateTime<Utc>, failed_attempts: usize, ) -> Result<JobLifecycleState, Error>
Derives the canonical lifecycle state from this persisted job and attempt history.
failed_attempts is the number of durable failed JobAttempt rows for this job.
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>,
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>,
Option<String>: 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>,
Option<DateTime<Utc>>: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
Option<i64>: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
i32: 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>,
Option<String>: 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>,
Option<DateTime<Utc>>: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
Option<i64>: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
i32: 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,
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
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> ⓘ
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> ⓘ
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