pub struct FailedJob {
pub id: i32,
pub job_id: i32,
pub payload: String,
pub attempts: i32,
pub reason: String,
pub failed_at: NaiveDateTime,
}Expand description
Represents a failed job record in the database.
Corresponds to the failed_jobs table in the database, and
stores information about jobs that have failed execution.
§Fields
id: Primary key of the failed job record.job_id: The originalidof the failed job from thejobstable.payload: The serialized data for the job (e.g. parameters or settings).attempts: Number of attempts that were made to run the job.reason: Description or reason why the job failed.failed_at: Timestamp (UTC or local) of when the job failed.
Fields§
§id: i32§job_id: i32§payload: String§attempts: i32§reason: String§failed_at: NaiveDateTimeImplementations§
Source§impl FailedJob
impl FailedJob
Sourcepub fn create(job: &Job, _reason: &str) -> Result<(), Error>
pub fn create(job: &Job, _reason: &str) -> Result<(), Error>
Creates a new record in the failed_jobs table based on a failed Job.
This function:
- Constructs a
NewFailedJobusing information from the providedJob. - Attempts to obtain a database connection via
DB::get_conn. - Inserts the new record into the
failed_jobstable using Diesel.
§Parameters
job: The job that failed, containing its ID, payload, and attempt count._reason: A string that describes the reason for the failure.
§Returns
Ok(())if the record was inserted successfully.Err(diesel::result::Error)if the operation fails (e.g. unable to get a DB connection or insert fails).
§Errors
Returns diesel::result::Error::NotFound if a database connection cannot be acquired.
Otherwise, returns a more specific Diesel error if the insert fails.
§Example
// Pseudocode for handling a failed job:
use zirv_queue::models::job::Job;
use zirv_queue::models::failed_job::FailedJob;
// Suppose `some_failed_job` is an instance of `Job`
let some_failed_job = Job {
id: 1,
payload: "some payload".to_string(),
attempts: 3,
available_at: chrono::Local::now().naive_local(),
created_at: chrono::Local::now().naive_local(),
updated_at: chrono::Local::now().naive_local(),
status: "failed".to_string(),
};
let reason = "Timed out.".to_string();
match FailedJob::create(some_failed_job, reason) {
Ok(_) => println!("Failed job record inserted."),
Err(e) => eprintln!("Error inserting failed job: {:?}", e),
}Trait Implementations§
Source§impl<'de> Deserialize<'de> for FailedJob
impl<'de> Deserialize<'de> for FailedJob
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
Source§impl<'insert> Insertable<table> for &'insert FailedJob
impl<'insert> Insertable<table> for &'insert FailedJob
Source§type Values = <(Option<Grouped<Eq<id, <&'insert i32 as AsExpression<<id as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<job_id, <&'insert i32 as AsExpression<<job_id as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<payload, <&'insert String as AsExpression<<payload as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<attempts, <&'insert i32 as AsExpression<<attempts as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<reason, <&'insert String as AsExpression<<reason as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<failed_at, <&'insert NaiveDateTime as AsExpression<<failed_at as Expression>::SqlType>>::Expression>>>) as Insertable<table>>::Values
type Values = <(Option<Grouped<Eq<id, <&'insert i32 as AsExpression<<id as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<job_id, <&'insert i32 as AsExpression<<job_id as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<payload, <&'insert String as AsExpression<<payload as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<attempts, <&'insert i32 as AsExpression<<attempts as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<reason, <&'insert String as AsExpression<<reason as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<failed_at, <&'insert NaiveDateTime as AsExpression<<failed_at as Expression>::SqlType>>::Expression>>>) as Insertable<table>>::Values
The
VALUES clause to insert these records Read moreSource§fn values(
self,
) -> <(Option<Eq<id, &'insert i32>>, Option<Eq<job_id, &'insert i32>>, Option<Eq<payload, &'insert String>>, Option<Eq<attempts, &'insert i32>>, Option<Eq<reason, &'insert String>>, Option<Eq<failed_at, &'insert NaiveDateTime>>) as Insertable<table>>::Values
fn values( self, ) -> <(Option<Eq<id, &'insert i32>>, Option<Eq<job_id, &'insert i32>>, Option<Eq<payload, &'insert String>>, Option<Eq<attempts, &'insert i32>>, Option<Eq<reason, &'insert String>>, Option<Eq<failed_at, &'insert NaiveDateTime>>) as Insertable<table>>::Values
Construct
Self::Values Read moreSource§fn insert_into(self, table: T) -> InsertStatement<T, Self::Values>
fn insert_into(self, table: T) -> InsertStatement<T, Self::Values>
Insert
self into a given table. Read moreSource§impl Insertable<table> for FailedJob
impl Insertable<table> for FailedJob
Source§type Values = <(Option<Grouped<Eq<id, <i32 as AsExpression<<id as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<job_id, <i32 as AsExpression<<job_id as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<payload, <String as AsExpression<<payload as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<attempts, <i32 as AsExpression<<attempts as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<reason, <String as AsExpression<<reason as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<failed_at, <NaiveDateTime as AsExpression<<failed_at as Expression>::SqlType>>::Expression>>>) as Insertable<table>>::Values
type Values = <(Option<Grouped<Eq<id, <i32 as AsExpression<<id as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<job_id, <i32 as AsExpression<<job_id as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<payload, <String as AsExpression<<payload as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<attempts, <i32 as AsExpression<<attempts as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<reason, <String as AsExpression<<reason as Expression>::SqlType>>::Expression>>>, Option<Grouped<Eq<failed_at, <NaiveDateTime as AsExpression<<failed_at as Expression>::SqlType>>::Expression>>>) as Insertable<table>>::Values
The
VALUES clause to insert these records Read moreSource§fn values(
self,
) -> <(Option<Eq<id, i32>>, Option<Eq<job_id, i32>>, Option<Eq<payload, String>>, Option<Eq<attempts, i32>>, Option<Eq<reason, String>>, Option<Eq<failed_at, NaiveDateTime>>) as Insertable<table>>::Values
fn values( self, ) -> <(Option<Eq<id, i32>>, Option<Eq<job_id, i32>>, Option<Eq<payload, String>>, Option<Eq<attempts, i32>>, Option<Eq<reason, String>>, Option<Eq<failed_at, NaiveDateTime>>) as Insertable<table>>::Values
Construct
Self::Values Read moreSource§fn insert_into(self, table: T) -> InsertStatement<T, Self::Values>
fn insert_into(self, table: T) -> InsertStatement<T, Self::Values>
Insert
self into a given table. Read moreSource§impl<__DB: Backend, __ST0, __ST1, __ST2, __ST3, __ST4, __ST5> Queryable<(__ST0, __ST1, __ST2, __ST3, __ST4, __ST5), __DB> for FailedJobwhere
(i32, i32, String, i32, String, NaiveDateTime): FromStaticSqlRow<(__ST0, __ST1, __ST2, __ST3, __ST4, __ST5), __DB>,
impl<__DB: Backend, __ST0, __ST1, __ST2, __ST3, __ST4, __ST5> Queryable<(__ST0, __ST1, __ST2, __ST3, __ST4, __ST5), __DB> for FailedJobwhere
(i32, i32, String, i32, String, NaiveDateTime): FromStaticSqlRow<(__ST0, __ST1, __ST2, __ST3, __ST4, __ST5), __DB>,
impl UndecoratedInsertRecord<table> for FailedJob
Auto Trait Implementations§
impl Freeze for FailedJob
impl RefUnwindSafe for FailedJob
impl Send for FailedJob
impl Sync for FailedJob
impl Unpin for FailedJob
impl UnwindSafe for FailedJob
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Add an aggregate function filter Read more
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
Add an aggregate function order Read more
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
Convert
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
Convert
&self to an expression for Diesel’s query builder. Read moreSource§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
Source§impl<T, ST, DB> StaticallySizedRow<ST, DB> for T
impl<T, ST, DB> StaticallySizedRow<ST, DB> for T
Source§const FIELD_COUNT: usize = <ST as crate::util::TupleSize>::SIZE
const FIELD_COUNT: usize = <ST as crate::util::TupleSize>::SIZE
The number of fields that this type will consume.
Source§impl<T> WindowExpressionMethods for T
impl<T> WindowExpressionMethods for T
Source§fn over(self) -> Self::Outputwhere
Self: OverDsl,
fn over(self) -> Self::Outputwhere
Self: OverDsl,
Turn a function call into a window function call Read more
Source§fn window_filter<P>(self, f: P) -> Self::Output
fn window_filter<P>(self, f: P) -> Self::Output
Add a filter to the current window function Read more
Source§fn partition_by<E>(self, expr: E) -> Self::Outputwhere
Self: PartitionByDsl<E>,
fn partition_by<E>(self, expr: E) -> Self::Outputwhere
Self: PartitionByDsl<E>,
Add a partition clause to the current window function Read more
Source§fn window_order<E>(self, expr: E) -> Self::Outputwhere
Self: OrderWindowDsl<E>,
fn window_order<E>(self, expr: E) -> Self::Outputwhere
Self: OrderWindowDsl<E>,
Add a order clause to the current window function Read more