pub struct Job {Show 13 fields
pub id: JobId,
pub job_type: String,
pub data: JobData,
pub priority: JobPriority,
pub status: JobStatus,
pub attempts: u32,
pub max_attempts: u32,
pub queue: String,
pub created_at: DateTime<Utc>,
pub scheduled_at: Option<DateTime<Utc>>,
pub started_at: Option<DateTime<Utc>>,
pub completed_at: Option<DateTime<Utc>>,
pub metadata: HashMap<String, String>,
}Expand description
A job to be processed.
Fields§
§id: JobIdUnique job identifier
job_type: StringJob type/name
data: JobDataJob payload data
priority: JobPriorityJob priority
status: JobStatusJob status
attempts: u32Number of attempts
max_attempts: u32Maximum number of retry attempts
queue: StringQueue name
created_at: DateTime<Utc>When the job was created
scheduled_at: Option<DateTime<Utc>>When the job should be processed (for delayed jobs)
started_at: Option<DateTime<Utc>>When the job was started
completed_at: Option<DateTime<Utc>>When the job completed/failed
metadata: HashMap<String, String>Job metadata
Implementations§
Source§impl Job
impl Job
Sourcepub fn new(
queue: impl Into<String>,
job_type: impl Into<String>,
data: JobData,
) -> Self
pub fn new( queue: impl Into<String>, job_type: impl Into<String>, data: JobData, ) -> Self
Create a new job.
Sourcepub fn with_priority(self, priority: JobPriority) -> Self
pub fn with_priority(self, priority: JobPriority) -> Self
Set job priority.
Sourcepub fn with_max_attempts(self, max_attempts: u32) -> Self
pub fn with_max_attempts(self, max_attempts: u32) -> Self
Set max retry attempts.
Sourcepub fn schedule_at(self, time: DateTime<Utc>) -> Self
pub fn schedule_at(self, time: DateTime<Utc>) -> Self
Schedule the job for later.
Sourcepub fn schedule_after(self, duration: Duration) -> Self
pub fn schedule_after(self, duration: Duration) -> Self
Schedule the job after a delay.
Sourcepub fn with_metadata(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_metadata( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add metadata.
Sourcepub fn start_processing(&mut self)
pub fn start_processing(&mut self)
Mark job as processing.
Sourcepub fn update_progress(&mut self, progress: u8, message: Option<String>)
pub fn update_progress(&mut self, progress: u8, message: Option<String>)
Update job progress.
Sourcepub fn backoff_delay(&self) -> Duration
pub fn backoff_delay(&self) -> Duration
Calculate backoff delay for retry.
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