pub trait JobQueue:
Send
+ Sync
+ 'static {
// Required methods
fn enqueue(
&self,
job: QueuedJob,
) -> impl Future<Output = Result<(), QueueError>> + Send;
fn claim(
&self,
worker_id: &str,
worker_labels: &[String],
lease_ttl: Duration,
) -> impl Future<Output = Result<Option<(QueuedJob, Lease)>, QueueError>> + Send;
fn renew_lease(
&self,
lease_id: &str,
extend_by: Duration,
) -> impl Future<Output = Result<(), QueueError>> + Send;
fn complete(
&self,
lease_id: &str,
outputs: HashMap<String, String>,
) -> impl Future<Output = Result<(), QueueError>> + Send;
fn fail(
&self,
lease_id: &str,
error: String,
retryable: bool,
) -> impl Future<Output = Result<(), QueueError>> + Send;
fn cancel(
&self,
workflow_id: &str,
job_id: &str,
) -> impl Future<Output = Result<(), QueueError>> + Send;
fn cancel_workflow(
&self,
workflow_id: &str,
) -> impl Future<Output = Result<(), QueueError>> + Send;
fn is_cancelled(
&self,
workflow_id: &str,
job_id: &str,
) -> impl Future<Output = Result<bool, QueueError>> + Send;
fn reap_expired_leases(
&self,
) -> impl Future<Output = Result<Vec<JobEvent>, QueueError>> + Send;
fn subscribe(&self) -> Receiver<JobEvent>;
}Expand description
Pluggable job queue backend.
Implementations: InMemoryJobQueue, PgBossJobQueue (Postgres), RedisJobQueue.
pg-boss mapping:
enqueue()→boss.send(queue, data, options)claim()→boss.fetch(queue)(SELECT … FOR UPDATE SKIP LOCKED)complete()→boss.complete(jobId)fail()→boss.fail(jobId)cancel()→boss.cancel(jobId)
Required Methods§
Sourcefn enqueue(
&self,
job: QueuedJob,
) -> impl Future<Output = Result<(), QueueError>> + Send
fn enqueue( &self, job: QueuedJob, ) -> impl Future<Output = Result<(), QueueError>> + Send
Enqueue a job for execution. Called by the scheduler when dependencies are met.
Sourcefn claim(
&self,
worker_id: &str,
worker_labels: &[String],
lease_ttl: Duration,
) -> impl Future<Output = Result<Option<(QueuedJob, Lease)>, QueueError>> + Send
fn claim( &self, worker_id: &str, worker_labels: &[String], lease_ttl: Duration, ) -> impl Future<Output = Result<Option<(QueuedJob, Lease)>, QueueError>> + Send
Atomically claim the next available job matching the worker’s labels.
Returns None if no matching job is available.
Sourcefn renew_lease(
&self,
lease_id: &str,
extend_by: Duration,
) -> impl Future<Output = Result<(), QueueError>> + Send
fn renew_lease( &self, lease_id: &str, extend_by: Duration, ) -> impl Future<Output = Result<(), QueueError>> + Send
Renew a lease (heartbeat). Returns error if the lease has already expired.
Sourcefn complete(
&self,
lease_id: &str,
outputs: HashMap<String, String>,
) -> impl Future<Output = Result<(), QueueError>> + Send
fn complete( &self, lease_id: &str, outputs: HashMap<String, String>, ) -> impl Future<Output = Result<(), QueueError>> + Send
Complete a job successfully. Releases the lease and stores outputs.
Sourcefn fail(
&self,
lease_id: &str,
error: String,
retryable: bool,
) -> impl Future<Output = Result<(), QueueError>> + Send
fn fail( &self, lease_id: &str, error: String, retryable: bool, ) -> impl Future<Output = Result<(), QueueError>> + Send
Fail a job. The queue decides whether to re-enqueue based on RetryPolicy.
Sourcefn cancel(
&self,
workflow_id: &str,
job_id: &str,
) -> impl Future<Output = Result<(), QueueError>> + Send
fn cancel( &self, workflow_id: &str, job_id: &str, ) -> impl Future<Output = Result<(), QueueError>> + Send
Cancel a specific job. If currently claimed, marks it for cancellation.
Sourcefn cancel_workflow(
&self,
workflow_id: &str,
) -> impl Future<Output = Result<(), QueueError>> + Send
fn cancel_workflow( &self, workflow_id: &str, ) -> impl Future<Output = Result<(), QueueError>> + Send
Cancel all jobs for a workflow.
Sourcefn is_cancelled(
&self,
workflow_id: &str,
job_id: &str,
) -> impl Future<Output = Result<bool, QueueError>> + Send
fn is_cancelled( &self, workflow_id: &str, job_id: &str, ) -> impl Future<Output = Result<bool, QueueError>> + Send
Check if a job has been marked for cancellation (workers poll this).
Sourcefn reap_expired_leases(
&self,
) -> impl Future<Output = Result<Vec<JobEvent>, QueueError>> + Send
fn reap_expired_leases( &self, ) -> impl Future<Output = Result<Vec<JobEvent>, QueueError>> + Send
Collect expired leases and emit LeaseExpired events. Called periodically by the server’s monitor task.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.