pub trait Backend {
// Required methods
fn subscribe_ready_jobs<'life0, 'async_trait>(
&'life0 self,
executor_identifier: ExecutorIdentifier,
) -> Pin<Box<dyn Future<Output = Pin<Box<dyn Stream<Item = Result<Job, BackendError>> + Send>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn enqueue<'a, 'life0, 'async_trait>(
&'life0 self,
job: EnqueuableJob<'a>,
) -> Pin<Box<dyn Future<Output = Result<JobId, BackendError>> + Send + 'async_trait>>
where Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait;
fn mark_job_complete<'life0, 'async_trait>(
&'life0 self,
id: JobId,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn mark_job_retryable<'life0, 'async_trait>(
&'life0 self,
id: JobId,
next_scheduled_at: DateTime<Utc>,
error: ExecutionError,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn mark_job_discarded<'life0, 'async_trait>(
&'life0 self,
id: JobId,
error: ExecutionError,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn mark_job_cancelled<'life0, 'async_trait>(
&'life0 self,
id: JobId,
error: ExecutionError,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn mark_job_snoozed<'life0, 'async_trait>(
&'life0 self,
id: JobId,
next_scheduled_at: DateTime<Utc>,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn prune_jobs<'life0, 'life1, 'async_trait>(
&'life0 self,
prune_spec: &'life1 PruneSpec,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn rerun_job<'life0, 'async_trait>(
&'life0 self,
job_id: JobId,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn update_job<'life0, 'async_trait>(
&'life0 self,
job: Job,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn query<'a, 'life0, 'async_trait>(
&'life0 self,
query: Query<'a>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Job>, BackendError>> + Send + 'async_trait>>
where Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait;
}Expand description
The trait which need to be implemented to create a backend for rexecutor.
Note: the decision was taken to have a subscribe to ready jobs function to enable implementers to make best use of their backend technology such as pgnotify or other DB level subscriptions.
Required Methods§
Sourcefn subscribe_ready_jobs<'life0, 'async_trait>(
&'life0 self,
executor_identifier: ExecutorIdentifier,
) -> Pin<Box<dyn Future<Output = Pin<Box<dyn Stream<Item = Result<Job, BackendError>> + Send>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn subscribe_ready_jobs<'life0, 'async_trait>(
&'life0 self,
executor_identifier: ExecutorIdentifier,
) -> Pin<Box<dyn Future<Output = Pin<Box<dyn Stream<Item = Result<Job, BackendError>> + Send>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Returns a stream of the jobs ready to be executed.
Note: this should avoid giving the same jobs to multiple instances of rexecutor. This is important for the correctness of the library when running in a cluster a locking mechanism should be used to avoid multiple instances processing the same job.
Sourcefn enqueue<'a, 'life0, 'async_trait>(
&'life0 self,
job: EnqueuableJob<'a>,
) -> Pin<Box<dyn Future<Output = Result<JobId, BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
fn enqueue<'a, 'life0, 'async_trait>(
&'life0 self,
job: EnqueuableJob<'a>,
) -> Pin<Box<dyn Future<Output = Result<JobId, BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
Enqueue a job to the backend.
Note: if this is scheduled for now or in the past this should immediately be passed to one of the subscribers.
Sourcefn mark_job_complete<'life0, 'async_trait>(
&'life0 self,
id: JobId,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn mark_job_complete<'life0, 'async_trait>(
&'life0 self,
id: JobId,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Mark a job as having been completed.
Sourcefn mark_job_retryable<'life0, 'async_trait>(
&'life0 self,
id: JobId,
next_scheduled_at: DateTime<Utc>,
error: ExecutionError,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn mark_job_retryable<'life0, 'async_trait>(
&'life0 self,
id: JobId,
next_scheduled_at: DateTime<Utc>,
error: ExecutionError,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Mark a job as retryable and schedule to run it again at the given instance.
Note this should record the error as part of the jobs errors array.
When the job next runs its attempt count should have been incremented.
Sourcefn mark_job_discarded<'life0, 'async_trait>(
&'life0 self,
id: JobId,
error: ExecutionError,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn mark_job_discarded<'life0, 'async_trait>(
&'life0 self,
id: JobId,
error: ExecutionError,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Mark a job as discarded (this is the state where the job has failed to complete successfully after reaching its max_attempts.
Note this should record the error as part of the jobs errors array.
Sourcefn mark_job_cancelled<'life0, 'async_trait>(
&'life0 self,
id: JobId,
error: ExecutionError,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn mark_job_cancelled<'life0, 'async_trait>(
&'life0 self,
id: JobId,
error: ExecutionError,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Mark a job as cancelled.
Note this should record the error as part of the jobs errors array.
Sourcefn mark_job_snoozed<'life0, 'async_trait>(
&'life0 self,
id: JobId,
next_scheduled_at: DateTime<Utc>,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn mark_job_snoozed<'life0, 'async_trait>(
&'life0 self,
id: JobId,
next_scheduled_at: DateTime<Utc>,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Mark a job as snoozed.
Note: this should not increment the attempt count.
Sourcefn prune_jobs<'life0, 'life1, 'async_trait>(
&'life0 self,
prune_spec: &'life1 PruneSpec,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn prune_jobs<'life0, 'life1, 'async_trait>(
&'life0 self,
prune_spec: &'life1 PruneSpec,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Remove the jobs according to the provided PruneSpec.
Sourcefn rerun_job<'life0, 'async_trait>(
&'life0 self,
job_id: JobId,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn rerun_job<'life0, 'async_trait>(
&'life0 self,
job_id: JobId,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Rerun the given job.
This should work for jobs that have completed, been discarded, or cancelled.