Crates.io | job_queue |
lib.rs | job_queue |
version | 0.0.20 |
source | src |
created_at | 2023-11-18 01:43:30.737767 |
updated_at | 2023-12-29 11:18:42.511574 |
description | A simple, efficient Rust library for handling asynchronous job processing and task queuing. |
homepage | |
repository | https://github.com/KABBOUCHI/job_queue |
max_upload_size | |
id | 1040138 |
size | 31,752 |
cargo add job_queue
use job_queue::{Error, Job, typetag, async_trait, serde};
#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[serde(crate = "job_queue::serde")]
pub struct HelloJob {
pub message: String,
}
#[async_trait::async_trait]
#[typetag::serde]
impl Job for HelloJob {
async fn handle(&self) -> Result<(), Error> {
println!("{}", self.message);
Ok(())
}
}
use job_queue::{Error, Job, Queue};
let queue = Client::builder()
.connect("mysql://root:@localhost/job_queue") // or postgres://root:@localhost/job_queue
.await?;
queue
.dispatch(&HelloJob {
message: "Hello, world!".to_string(),
})
.await?;
use job_queue::{Error, Job, Worker};
use std::time::Duration;
let worker = Worker::builder()
.max_connections(10)
.worker_count(10)
.connect("mysql://root:@localhost/job_queue") // or postgres://root:@localhost/job_queue
.await?;
worker.start().await?; // blocks forever, or until all workers are stopped (crash or ctrl-c)
TODO: