Struct faktory::JobBuilder
source · pub struct JobBuilder { /* private fields */ }
Expand description
Builder for Job
.
Implementations§
source§impl JobBuilder
impl JobBuilder
sourcepub fn expires_at(&mut self, dt: DateTime<Utc>) -> &mut Self
Available on crate feature ent
only.
pub fn expires_at(&mut self, dt: DateTime<Utc>) -> &mut Self
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();
sourcepub fn expires_in(&mut self, ttl: Duration) -> &mut Self
Available on crate feature ent
only.
pub fn expires_in(&mut self, ttl: Duration) -> &mut Self
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();
sourcepub fn unique_for(&mut self, secs: usize) -> &mut Self
Available on crate feature ent
only.
pub fn unique_for(&mut self, secs: usize) -> &mut Self
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.
sourcepub fn unique_until_start(&mut self) -> &mut Self
Available on crate feature ent
only.
pub fn unique_until_start(&mut self) -> &mut Self
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).
sourcepub fn unique_until_success(&mut self) -> &mut Self
Available on crate feature ent
only.
pub fn unique_until_success(&mut self) -> &mut Self
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
impl JobBuilder
sourcepub fn jid<VALUE: Into<String>>(&mut self, value: VALUE) -> &mut Self
pub fn jid<VALUE: Into<String>>(&mut self, value: VALUE) -> &mut Self
The job’s unique identifier.
sourcepub fn queue<VALUE: Into<String>>(&mut self, value: VALUE) -> &mut Self
pub fn queue<VALUE: Into<String>>(&mut self, value: VALUE) -> &mut Self
The queue this job belongs to. Usually default
.
sourcepub fn created_at<VALUE: Into<Option<DateTime<Utc>>>>(
&mut self,
value: VALUE
) -> &mut Self
pub fn created_at<VALUE: Into<Option<DateTime<Utc>>>>( &mut self, value: VALUE ) -> &mut Self
When this job was created.
sourcepub fn at<VALUE: Into<Option<DateTime<Utc>>>>(
&mut self,
value: VALUE
) -> &mut Self
pub fn at<VALUE: Into<Option<DateTime<Utc>>>>( &mut self, value: VALUE ) -> &mut Self
When this job is scheduled for.
Defaults to immediately.
sourcepub fn reserve_for<VALUE: Into<Option<usize>>>(
&mut self,
value: VALUE
) -> &mut Self
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.
sourcepub fn retry<VALUE: Into<Option<isize>>>(&mut self, value: VALUE) -> &mut Self
pub fn retry<VALUE: Into<Option<isize>>>(&mut self, value: VALUE) -> &mut Self
Number of times to retry this job.
Defaults to 25.
sourcepub fn priority<VALUE: Into<Option<u8>>>(&mut self, value: VALUE) -> &mut Self
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.
sourcepub fn backtrace<VALUE: Into<Option<usize>>>(
&mut self,
value: VALUE
) -> &mut Self
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.
sourcepub fn custom<VALUE: Into<HashMap<String, Value>>>(
&mut self,
value: VALUE
) -> &mut Self
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
impl JobBuilder
sourcepub fn args<A>(&mut self, args: Vec<A>) -> &mut Self
pub fn args<A>(&mut self, args: Vec<A>) -> &mut Self
Setter for the arguments provided for this job.
sourcepub fn add_to_custom_data(
&mut self,
k: impl Into<String>,
v: impl Into<Value>
) -> &mut Self
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.
sourcepub fn build(&mut self) -> Job
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
impl Clone for JobBuilder
source§fn clone(&self) -> JobBuilder
fn clone(&self) -> JobBuilder
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more