pub struct Job {
pub id: String,
pub job_type: String,
pub payload: HashMap<String, Value>,
pub priority: JobPriority,
pub status: JobStatus,
pub max_retries: u32,
pub retry_count: u32,
pub created_at: DateTime<Utc>,
pub scheduled_at: Option<DateTime<Utc>>,
pub started_at: Option<DateTime<Utc>>,
pub completed_at: Option<DateTime<Utc>>,
pub timeout_seconds: Option<u64>,
}Expand description
A durable background job
Fields§
§id: String§job_type: String§payload: HashMap<String, Value>§priority: JobPriority§status: JobStatus§max_retries: u32§retry_count: u32§created_at: DateTime<Utc>§scheduled_at: Option<DateTime<Utc>>§started_at: Option<DateTime<Utc>>§completed_at: Option<DateTime<Utc>>§timeout_seconds: Option<u64>Implementations§
Source§impl Job
impl Job
Sourcepub fn with_payload(self, payload: HashMap<String, Value>) -> Self
pub fn with_payload(self, payload: HashMap<String, Value>) -> Self
Set job payload
Sourcepub fn add_field(self, key: impl Into<String>, value: Value) -> Self
pub fn add_field(self, key: impl Into<String>, value: Value) -> Self
Add a single payload field
Sourcepub fn with_priority(self, priority: JobPriority) -> Self
pub fn with_priority(self, priority: JobPriority) -> Self
Set job priority
Sourcepub fn with_max_retries(self, max_retries: u32) -> Self
pub fn with_max_retries(self, max_retries: u32) -> Self
Set max retries
Sourcepub fn scheduled_at(self, at: DateTime<Utc>) -> Self
pub fn scheduled_at(self, at: DateTime<Utc>) -> Self
Schedule job for later execution
Sourcepub fn with_timeout(self, seconds: u64) -> Self
pub fn with_timeout(self, seconds: u64) -> Self
Set job timeout
Sourcepub fn should_run(&self) -> bool
pub fn should_run(&self) -> bool
Check if job should be executed (based on schedule)
Sourcepub fn mark_running(&mut self)
pub fn mark_running(&mut self)
Mark job as running
Sourcepub fn mark_completed(&mut self)
pub fn mark_completed(&mut self)
Mark job as completed
Sourcepub fn mark_failed(&mut self, error: String)
pub fn mark_failed(&mut self, error: String)
Mark job as failed
Sourcepub fn next_retry_delay(&self) -> Duration
pub fn next_retry_delay(&self) -> Duration
Calculate next retry delay (exponential backoff)
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 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