pub trait JobHandler:
Send
+ Sync
+ Serialize
+ DeserializeOwned
+ Clone {
// Required method
fn execute(
&self,
ctx: &JobContext,
) -> impl Future<Output = Result<JobResult, QueueError>> + Send;
// Provided method
fn job_type(&self) -> &str { ... }
}Expand description
Trait that job types must implement to be processed by the queue.
Your job type must be serializable (stored as JSON in SQLite), cloneable, and thread-safe.
§Example
ⓘ
use serde::{Serialize, Deserialize};
use agent_queue::*;
#[derive(Debug, Clone, Serialize, Deserialize)]
struct EmailJob {
to: String,
subject: String,
}
impl JobHandler for EmailJob {
async fn execute(&self, ctx: &JobContext) -> Result<JobResult, QueueError> {
// Send email...
ctx.emit_progress(1, 1);
Ok(JobResult::success())
}
}Required Methods§
Sourcefn execute(
&self,
ctx: &JobContext,
) -> impl Future<Output = Result<JobResult, QueueError>> + Send
fn execute( &self, ctx: &JobContext, ) -> impl Future<Output = Result<JobResult, QueueError>> + Send
Execute the job. This is called by the executor when the job is picked up.
Use ctx.emit_progress() to report progress and ctx.is_cancelled()
to check for cancellation during long-running operations.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".