FailedJob

Struct FailedJob 

Source
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 original id of the failed job from the jobs table.
  • 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: NaiveDateTime

Implementations§

Source§

impl FailedJob

Source

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:

  1. Constructs a NewFailedJob using information from the provided Job.
  2. Attempts to obtain a database connection via DB::get_conn.
  3. Inserts the new record into the failed_jobs table 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 Debug for FailedJob

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for FailedJob

Source§

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

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

The VALUES clause to insert these records Read more
Source§

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 more
Source§

fn insert_into(self, table: T) -> InsertStatement<T, Self::Values>
where T: Table, Self: Sized,

Insert self into a given table. Read more
Source§

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

The VALUES clause to insert these records Read more
Source§

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 more
Source§

fn insert_into(self, table: T) -> InsertStatement<T, Self::Values>
where T: Table, Self: Sized,

Insert self into a given table. Read more
Source§

impl<__DB: Backend, __ST0, __ST1, __ST2, __ST3, __ST4, __ST5> Queryable<(__ST0, __ST1, __ST2, __ST3, __ST4, __ST5), __DB> for FailedJob

Source§

type Row = (i32, i32, String, i32, String, NaiveDateTime)

The Rust type you’d like to map from. Read more
Source§

fn build(row: (i32, i32, String, i32, String, NaiveDateTime)) -> Result<Self>

Construct an instance of this type
Source§

impl Serialize for FailedJob

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl UndecoratedInsertRecord<table> for FailedJob

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AggregateExpressionMethods for T

Source§

fn aggregate_distinct(self) -> Self::Output
where Self: DistinctDsl,

DISTINCT modifier for aggregate functions Read more
Source§

fn aggregate_all(self) -> Self::Output
where Self: AllDsl,

ALL modifier for aggregate functions Read more
Source§

fn aggregate_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add an aggregate function filter Read more
Source§

fn aggregate_order<O>(self, o: O) -> Self::Output
where Self: OrderAggregateDsl<O>,

Add an aggregate function order Read more
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

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>

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)

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)

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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T, ST, DB> StaticallySizedRow<ST, DB> for T
where ST: SqlTypeOrSelectable + TupleSize, T: Queryable<ST, DB>, DB: Backend,

Source§

const FIELD_COUNT: usize = <ST as crate::util::TupleSize>::SIZE

The number of fields that this type will consume.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WindowExpressionMethods for T

Source§

fn over(self) -> Self::Output
where Self: OverDsl,

Turn a function call into a window function call Read more
Source§

fn window_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add a filter to the current window function Read more
Source§

fn partition_by<E>(self, expr: E) -> Self::Output
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function Read more
Source§

fn window_order<E>(self, expr: E) -> Self::Output
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function Read more
Source§

fn frame_by<E>(self, expr: E) -> Self::Output
where Self: FrameDsl<E>,

Add a frame clause to the current window function Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,