pub trait JobProcessor: Sync + Send {
type Job: Send + 'static;
type JobId: Send + Sync + Debug + 'static;
type JobArtifacts: Send + 'static;
const SERVICE_NAME: &'static str;
const POLLING_INTERVAL_MS: u64 = 1000;
const MAX_BACKOFF_MS: u64 = 60_000;
const BACKOFF_MULTIPLIER: u64 = 2;
// Required methods
fn get_next_job<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<(Self::JobId, Self::Job)>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn save_failure<'life0, 'async_trait>(
&'life0 self,
job_id: Self::JobId,
started_at: Instant,
error: String,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn process_job<'life0, 'life1, 'async_trait>(
&'life0 self,
job_id: &'life1 Self::JobId,
job: Self::Job,
started_at: Instant,
) -> Pin<Box<dyn Future<Output = JoinHandle<Result<Self::JobArtifacts>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn save_result<'life0, 'async_trait>(
&'life0 self,
job_id: Self::JobId,
started_at: Instant,
artifacts: Self::JobArtifacts,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn max_attempts(&self) -> u32;
fn get_job_attempts<'life0, 'life1, 'async_trait>(
&'life0 self,
job_id: &'life1 Self::JobId,
) -> Pin<Box<dyn Future<Output = Result<u32>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn run<'async_trait>(
self,
stop_receiver: Receiver<bool>,
iterations_left: Option<usize>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: Sized + 'async_trait { ... }
fn wait_for_task<'life0, 'life1, 'async_trait>(
&'life0 self,
job_id: Self::JobId,
started_at: Instant,
task: JoinHandle<Result<Self::JobArtifacts>>,
stop_receiver: &'life1 mut Receiver<bool>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Required Associated Constants§
const SERVICE_NAME: &'static str
Provided Associated Constants§
const POLLING_INTERVAL_MS: u64 = 1000
const MAX_BACKOFF_MS: u64 = 60_000
const BACKOFF_MULTIPLIER: u64 = 2
Required Associated Types§
type Job: Send + 'static
type JobId: Send + Sync + Debug + 'static
type JobArtifacts: Send + 'static
Required Methods§
Sourcefn get_next_job<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<(Self::JobId, Self::Job)>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_next_job<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<(Self::JobId, Self::Job)>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Returns None when there is no pending job Otherwise, returns Some(job_id, job) Note: must be concurrency-safe - that is, one job must not be returned in two parallel processes
Sourcefn save_failure<'life0, 'async_trait>(
&'life0 self,
job_id: Self::JobId,
started_at: Instant,
error: String,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn save_failure<'life0, 'async_trait>(
&'life0 self,
job_id: Self::JobId,
started_at: Instant,
error: String,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Invoked when process_job panics
Should mark the job as failed
Sourcefn process_job<'life0, 'life1, 'async_trait>(
&'life0 self,
job_id: &'life1 Self::JobId,
job: Self::Job,
started_at: Instant,
) -> Pin<Box<dyn Future<Output = JoinHandle<Result<Self::JobArtifacts>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn process_job<'life0, 'life1, 'async_trait>(
&'life0 self,
job_id: &'life1 Self::JobId,
job: Self::Job,
started_at: Instant,
) -> Pin<Box<dyn Future<Output = JoinHandle<Result<Self::JobArtifacts>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Function that processes a job
Sourcefn save_result<'life0, 'async_trait>(
&'life0 self,
job_id: Self::JobId,
started_at: Instant,
artifacts: Self::JobArtifacts,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn save_result<'life0, 'async_trait>(
&'life0 self,
job_id: Self::JobId,
started_at: Instant,
artifacts: Self::JobArtifacts,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Invoked when process_job doesn’t panic
fn max_attempts(&self) -> u32
Provided Methods§
Sourcefn run<'async_trait>(
self,
stop_receiver: Receiver<bool>,
iterations_left: Option<usize>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: Sized + 'async_trait,
fn run<'async_trait>(
self,
stop_receiver: Receiver<bool>,
iterations_left: Option<usize>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: Sized + 'async_trait,
iterations_left:
To run indefinitely, pass None,
To process one job, pass Some(1),
To process a batch, pass Some(batch_size).
Sourcefn wait_for_task<'life0, 'life1, 'async_trait>(
&'life0 self,
job_id: Self::JobId,
started_at: Instant,
task: JoinHandle<Result<Self::JobArtifacts>>,
stop_receiver: &'life1 mut Receiver<bool>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn wait_for_task<'life0, 'life1, 'async_trait>(
&'life0 self,
job_id: Self::JobId,
started_at: Instant,
task: JoinHandle<Result<Self::JobArtifacts>>,
stop_receiver: &'life1 mut Receiver<bool>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Polls task handle, saving its outcome.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".