ProcessedJob

Struct ProcessedJob 

Source
pub struct ProcessedJob {
    pub id: i32,
    pub job_id: i32,
    pub return_value: String,
    pub payload: String,
    pub attempts: i32,
    pub processed_at: NaiveDateTime,
}
Expand description

Represents a successfully processed job record in the database.

This corresponds to the processed_jobs table, which stores details of jobs that have been completed. It can be used for auditing, logging, or debugging purposes after a job is removed from the active jobs table.

§Fields

  • id: Primary key (database-generated).
  • job_id: The original id from the jobs table.
  • return_value: Data returned when the job was processed (e.g., a result string).
  • payload: The job’s original payload (e.g., parameters).
  • attempts: The number of attempts made to run this job before it was completed.
  • processed_at: The timestamp indicating when the job was processed.

Fields§

§id: i32§job_id: i32§return_value: String§payload: String§attempts: i32§processed_at: NaiveDateTime

Implementations§

Source§

impl ProcessedJob

Source

pub fn create(job: &Job, _return_value: String) -> Result<(), Error>

Creates a new record in the processed_jobs table based on a completed Job.

This method:

  1. Constructs a NewProcessedJob from the provided Job data and a user-provided return value string.
  2. Acquires a database connection via DB::get_conn.
  3. Inserts the NewProcessedJob into the processed_jobs table.
§Parameters
  • job: The Job that has been successfully completed.
  • _return_value: A string describing the outcome of the job (result data or message).
§Returns
  • Ok(()) if the record was inserted successfully.
  • Err(diesel::result::Error) if there is a connection or insertion failure.
§Example
// Suppose `some_job` is an instance of a `Job` that has completed successfully.
let some_job = Job {
    id: 1,
    payload: "example payload".to_string(),
    status: "completed".to_string(),
    attempts: 1,
    available_at: chrono::Local::now().naive_local(),
    created_at: chrono::Local::now().naive_local(),
    updated_at: chrono::Local::now().naive_local(),
};
 
let return_msg = "Processed successfully".to_string();

match ProcessedJob::create(some_job, return_msg) {
    Ok(_) => println!("Successfully inserted processed job record."),
    Err(e) => eprintln!("Failed to create processed job record: {:?}", e),
}

Trait Implementations§

Source§

impl Debug for ProcessedJob

Source§

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

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

impl<'de> Deserialize<'de> for ProcessedJob

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 ProcessedJob

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<return_value, <&'insert String as AsExpression<<return_value 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<processed_at, <&'insert NaiveDateTime as AsExpression<<processed_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<return_value, &'insert String>>, Option<Eq<payload, &'insert String>>, Option<Eq<attempts, &'insert i32>>, Option<Eq<processed_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 ProcessedJob

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<return_value, <String as AsExpression<<return_value 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<processed_at, <NaiveDateTime as AsExpression<<processed_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<return_value, String>>, Option<Eq<payload, String>>, Option<Eq<attempts, i32>>, Option<Eq<processed_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 ProcessedJob

Source§

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

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

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

Construct an instance of this type
Source§

impl Serialize for ProcessedJob

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 ProcessedJob

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,