Struct faktory::JobBuilder

source ·
pub struct JobBuilder { /* private fields */ }
Expand description

Builder for Job.

Implementations§

source§

impl JobBuilder

source

pub fn expires_at(&mut self, dt: DateTime<Utc>) -> &mut Self

Available on crate feature ent only.

When Faktory should expire this job.

Faktory Enterprise allows for expiring jobs. This is setter for expires_at field in the job’s custom data.

let _job = JobBuilder::new("order")
    .args(vec!["ISBN-14:9781718501850"])
    .expires_at(Utc::now() + Duration::hours(0))
    .build();
source

pub fn expires_in(&mut self, ttl: Duration) -> &mut Self

Available on crate feature ent only.

In what period of time from now (UTC) the Faktory should expire this job.

Under the hood, the method will call Utc::now and add the provided ttl duration. You can use this setter when you have a duration rather than some exact date and time, expected by expires_at setter. Example usage:

let _job = JobBuilder::new("order")
    .args(vec!["ISBN-14:9781718501850"])
    .expires_in(Duration::weeks(0))
    .build();
source

pub fn unique_for(&mut self, secs: usize) -> &mut Self

Available on crate feature ent only.

How long the Faktory will not accept duplicates of this job.

The job will be considered unique for the kind-args-queue combination. The uniqueness is best-effort, rather than a guarantee. Check out the Enterprise Faktory docs for details on how scheduling, retries, and other features live together with unique_for.

If you’ve already created and pushed a unique job (job “A”) to the Faktory server and now have got another one of same kind, with the same args and destined for the same queue (job “B”) and you would like - for some reason - to bypass the unique constraint, simply leave unique_for field on the job’s custom hash empty, i.e. do not use this setter. In this case, the Faktory server will accept job “B”, though technically this job “B” is a duplicate.

source

pub fn unique_until_start(&mut self) -> &mut Self

Available on crate feature ent only.

Remove unique lock for this job right before the job starts executing.

Another job with the same kind-args-queue combination will be accepted by the Faktory server after the period specified in unique_for has finished or after this job has been been consumed (i.e. its execution has started).

source

pub fn unique_until_success(&mut self) -> &mut Self

Available on crate feature ent only.

Do not remove unique lock for this job until it successfully finishes.

Sets unique_until on the Job’s custom hash to success, which is Faktory’s default. Another job with the same kind-args-queue combination will be accepted by the Faktory server after the period specified in unique_for has finished or after this job has been been successfully processed.

source§

impl JobBuilder

source

pub fn jid<VALUE: Into<String>>(&mut self, value: VALUE) -> &mut Self

The job’s unique identifier.

source

pub fn queue<VALUE: Into<String>>(&mut self, value: VALUE) -> &mut Self

The queue this job belongs to. Usually default.

source

pub fn created_at<VALUE: Into<Option<DateTime<Utc>>>>( &mut self, value: VALUE ) -> &mut Self

When this job was created.

source

pub fn at<VALUE: Into<Option<DateTime<Utc>>>>( &mut self, value: VALUE ) -> &mut Self

When this job is scheduled for.

Defaults to immediately.

source

pub fn reserve_for<VALUE: Into<Option<usize>>>( &mut self, value: VALUE ) -> &mut Self

How long to allow this job to run for.

Defaults to 600 seconds.

source

pub fn retry<VALUE: Into<Option<isize>>>(&mut self, value: VALUE) -> &mut Self

Number of times to retry this job.

Defaults to 25.

source

pub fn priority<VALUE: Into<Option<u8>>>(&mut self, value: VALUE) -> &mut Self

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.

source

pub fn backtrace<VALUE: Into<Option<usize>>>( &mut self, value: VALUE ) -> &mut Self

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

Defaults to 0.

source

pub fn custom<VALUE: Into<HashMap<String, Value>>>( &mut self, value: VALUE ) -> &mut Self

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.

source§

impl JobBuilder

source

pub fn new(kind: impl Into<String>) -> JobBuilder

Creates a new builder for a Job

source

pub fn args<A>(&mut self, args: Vec<A>) -> &mut Self
where A: Into<Value>,

Setter for the arguments provided for this job.

source

pub fn add_to_custom_data( &mut self, k: impl Into<String>, v: impl Into<Value> ) -> &mut Self

Sets arbitrary key-value pairs to this job’s custom data hash.

source

pub fn build(&mut self) -> Job

Builds a new Job from the parameters of this builder.

For Enterprise edition of Faktory builds a new trackable Job. In Enterprise Faktory, a progress update can be sent and received only for the jobs that have been explicitly marked as trackable via "track":1 in the job’s custom hash. In case you have a reason to opt out of tracking, either unset (remove) the “track” on the resulted job’s custom hash or set it to 0.

Trait Implementations§

source§

impl Clone for JobBuilder

source§

fn clone(&self) -> JobBuilder

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

Auto Trait Implementations§

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