aide-de-camp-mongodb
A MongoDB backed implementation of the job Queue for aide-de-camp.
Example
use aide_de_camp::prelude::{
CancellationToken, Duration, JobProcessor, JobRunner, Queue, RunnerOptions, RunnerRouter, Xid,
};
use aide_de_camp_mongodb::MongoDbQueue;
use async_trait::async_trait;
struct MyJob;
#[async_trait]
impl JobProcessor for MyJob {
type Payload = Vec<u32>;
type Error = anyhow::Error;
async fn handle(
&self,
_jid: Xid,
payload: Self::Payload,
_cancellation_token: CancellationToken,
) -> Result<(), Self::Error> {
println!("payload: {:?}", payload);
Ok(())
}
fn name() -> &'static str {
"my_job"
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let queue = MongoDbQueue::new("mongodb://localhost:27017/queues", None).await?;
let _jid = queue.schedule::<MyJob>(vec![1, 2, 3], 0).await?;
let router = {
let mut r = RunnerRouter::default();
r.add_job_handler(MyJob);
r
};
let mut runner = JobRunner::new(queue, router, 10, RunnerOptions::default());
runner
.run_with_shutdown(Duration::seconds(1), async move {
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
})
.await?;
Ok(())
}
License
I decided to follow the same licensing model as aide-de-camp, so be welcome to choose either of the following based on your use case:
Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)