Attribute Macro sqlxmq_macros::job[][src]

#[job]

Marks a function as being a background job.

The function must take a single CurrentJob argument, and should be async or return a future.

The async result must be a Result<(), E> type, where E is convertible to a Box<dyn Error + Send + Sync + 'static>, which is the case for most error types.

Several options can be provided to the #[job] attribute:

Name

#[job("example")]
#[job(name="example")]

This overrides the name for this job. If unspecified, the fully-qualified name of the function is used. If you move a job to a new module or rename the function, you may which to override the job name to prevent it from changing.

Channel name

#[job(channel_name="foo")]

This sets the default channel name on which the job will be spawned.

Retries

#[job(retries = 3)]

This sets the default number of retries for the job.

Retry backoff

#[job(backoff_secs=1.5)]
#[job(backoff_secs=2)]

This sets the default initial retry backoff for the job in seconds.

Ordered

#[job(ordered)]
#[job(ordered=true)]
#[job(ordered=false)]

This sets whether the job will be strictly ordered by default.

Prototype

fn my_proto<'a, 'b>(
    builder: &'a mut JobBuilder<'b>
) -> &'a mut JobBuilder<'b> {
    builder.set_channel_name("bar")
}

#[job(proto(my_proto))]

This allows setting several job options at once using the specified function, and can be convient if you have several jobs which should have similar defaults.

Combinations

Multiple job options can be combined. The order is not important, but the prototype will always be applied first so that explicit options can override it. Each option can only be provided once in the attribute.

#[job("my_job", proto(my_proto), retries=0, ordered)]