Expand description
A definition of a job, including the name of the job, the function that runs the job, and other settings.
The function that runs the job should be an async function that takes a RunningJob and a context object.
All jobs for a particular worker must have the same context type.
The function can be either a normal function or a closure.
#[derive(Debug)]
pub struct JobContext {
// database pool or other things here
}
let job = JobRunner::builder("a_job", |job: RunningJob, context: Arc<JobContext>| async move {
// do some work
Ok::<_, Error>("optional info about the success")
}).build();
async fn another_job(job: RunningJob, context: Arc<JobContext>) -> Result<String, Error> {
// do some work
Ok("optional info about the success".to_string())
}
let another_job = JobRunner::builder("another_job", another_job)
.autoheartbeat(true)
.build();Implementations
sourceimpl<CONTEXT> JobRunner<CONTEXT>where
CONTEXT: Send + Sync + Debug + Clone + 'static,
impl<CONTEXT> JobRunner<CONTEXT>where
CONTEXT: Send + Sync + Debug + Clone + 'static,
sourcepub fn new<F, Fut, T, E>(
name: impl Into<SmartString<LazyCompact>>,
runner: F,
autoheartbeat: bool
) -> JobRunner<CONTEXT>where
F: Fn(RunningJob, CONTEXT) -> Fut + Send + Sync + Clone + 'static,
CONTEXT: Send + Debug + Clone + 'static,
Fut: Future<Output = Result<T, E>> + Send + Sync,
T: Send + Sync + Debug + Serialize + 'static,
E: Send + Display + 'static,
pub fn new<F, Fut, T, E>(
name: impl Into<SmartString<LazyCompact>>,
runner: F,
autoheartbeat: bool
) -> JobRunner<CONTEXT>where
F: Fn(RunningJob, CONTEXT) -> Fut + Send + Sync + Clone + 'static,
CONTEXT: Send + Debug + Clone + 'static,
Fut: Future<Output = Result<T, E>> + Send + Sync,
T: Send + Sync + Debug + Serialize + 'static,
E: Send + Display + 'static,
Create a new JobRunner, passing all the possible fields. Generally it’s easier to use JobRunner::builder.
sourcepub fn builder<F, Fut, T, E>(
name: impl Into<SmartString<LazyCompact>>,
runner: F
) -> JobRunnerBuilder<CONTEXT>where
F: Fn(RunningJob, CONTEXT) -> Fut + Send + Sync + Clone + 'static,
CONTEXT: Send + Debug + Clone + 'static,
Fut: Future<Output = Result<T, E>> + Send + Sync,
T: Send + Sync + Debug + Serialize + 'static,
E: Send + Display + 'static,
pub fn builder<F, Fut, T, E>(
name: impl Into<SmartString<LazyCompact>>,
runner: F
) -> JobRunnerBuilder<CONTEXT>where
F: Fn(RunningJob, CONTEXT) -> Fut + Send + Sync + Clone + 'static,
CONTEXT: Send + Debug + Clone + 'static,
Fut: Future<Output = Result<T, E>> + Send + Sync,
T: Send + Sync + Debug + Serialize + 'static,
E: Send + Display + 'static,
Create a JobRunnerBuilder for this job.
Trait Implementations
Auto Trait Implementations
impl<CONTEXT> !RefUnwindSafe for JobRunner<CONTEXT>
impl<CONTEXT> Send for JobRunner<CONTEXT>
impl<CONTEXT> Sync for JobRunner<CONTEXT>
impl<CONTEXT> Unpin for JobRunner<CONTEXT>
impl<CONTEXT> !UnwindSafe for JobRunner<CONTEXT>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more