Struct faktory::Job

source ·
pub struct Job {
    pub queue: String,
    pub created_at: Option<DateTime<Utc>>,
    pub enqueued_at: Option<DateTime<Utc>>,
    pub at: Option<DateTime<Utc>>,
    pub reserve_for: Option<usize>,
    pub retry: Option<isize>,
    pub priority: Option<u8>,
    pub backtrace: Option<usize>,
    pub custom: HashMap<String, Value>,
    /* private fields */
}
Expand description

A Faktory job.

To create a job, use ‘Job::new’ specifying ‘kind’ and ‘args’:

use faktory::Job;

let _job = Job::new("order", vec!["ISBN-13:9781718501850"]);

Alternatively, use JobBuilder to configure more aspects of a job:

use faktory::JobBuilder;

let _job = JobBuilder::new("order")
    .args(vec!["ISBN-13:9781718501850"])
    .build();

Equivalently:

use faktory::Job;

let _job = Job::builder("order")
    .args(vec!["ISBN-13:9781718501850"])
    .build();

In case no arguments are expected ‘on the other side’, you can simply go with:

use faktory::Job;

let _job = Job::builder("rebuild_index").build();

See also the Faktory wiki.

Fields§

§queue: String

The queue this job belongs to. Usually default.

§created_at: Option<DateTime<Utc>>

When this job was created.

§enqueued_at: Option<DateTime<Utc>>

When this job was supplied to the Faktory server.

§at: Option<DateTime<Utc>>

When this job is scheduled for.

Defaults to immediately.

§reserve_for: Option<usize>

How long to allow this job to run for.

Defaults to 600 seconds.

§retry: Option<isize>

Number of times to retry this job.

Defaults to 25.

§priority: Option<u8>

The priority of this job from 1-9 (9 is highest).

Pushing a job with priority 9 will effectively put it at the front of the queue. Defaults to 5.

§backtrace: Option<usize>

Number of lines of backtrace to keep if this job fails.

Defaults to 0.

§custom: HashMap<String, Value>

Extra context to include with the job.

Faktory workers can have plugins and middleware which need to store additional context with the job payload. Faktory supports a custom hash to store arbitrary key/values in the JSON. This can be extremely helpful for cross-cutting concerns which should propagate between systems, e.g. locale for user-specific text translations, request_id for tracing execution across a complex distributed system, etc.

Implementations§

source§

impl Job

source

pub fn new<S, A>(kind: S, args: Vec<A>) -> Self
where S: Into<String>, A: Into<Value>,

Create a new job of type kind, with the given arguments.

source

pub fn builder<S: Into<String>>(kind: S) -> JobBuilder

Creates an ergonomic constructor for a new Job.

Also equivalent to JobBuilder::new.

source

pub fn on_queue<S: Into<String>>(self, queue: S) -> Self

Place this job on the given queue.

If this method is not called (or self.queue set otherwise), the queue will be set to “default”.

source

pub fn id(&self) -> &str

This job’s id.

source

pub fn kind(&self) -> &str

This job’s type.

source

pub fn args(&self) -> &[Value]

The arguments provided for this job.

source

pub fn failure(&self) -> &Option<Failure>

Data about this job’s most recent failure.

Trait Implementations§

source§

impl Clone for Job

source§

fn clone(&self) -> Job

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Job

source§

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

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

impl<'de> Deserialize<'de> for Job

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 Serialize for Job

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

Auto Trait Implementations§

§

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> 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> 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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

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