diff --git a/README.md b/README.md index 9d960b5..518bfc1 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,14 @@ Here are some of the Backie's key features: - Task timeout: Tasks are retried if they are not completed in time - Scheduling of tasks: Tasks can be scheduled to be executed at a specific time +## Safety + +This crate uses `#![forbid(unsafe_code)]` to ensure everything is implemented in 100% safe Rust. + +## Minimum supported Rust version + +Backie's MSRV is 1.68. + ## Installation 1. Add this to your `Cargo.toml` @@ -54,8 +62,6 @@ diesel-async = { version = "0.2", features = ["postgres", "bb8"] } Those dependencies are required to use the `#[async_trait]` and `#[derive(Serialize, Deserialize)]` attributes in your task definitions and to connect to the Postgres database. -*Supports rustc 1.68+* - 2. Create the `backie_tasks` table in the Postgres database. The migration can be found in [the migrations directory](https://github.com/rafaelcaricio/backie/blob/master/migrations/2023-03-06-151907_create_backie_tasks/up.sql). ## Usage @@ -114,6 +120,10 @@ This will enqueue the task and whenever a worker is available it will start proc started before enqueuing tasks. Workers don't need to be in the same process as the queue as long as the workers have access to the same underlying storage system. This enables horizontal scaling of the workers. +## License + +This project is licensed under the [MIT license][license]. + ## Contributing 1. [Fork it!](https://github.com/rafaelcaricio/backie/fork) @@ -122,7 +132,7 @@ access to the same underlying storage system. This enables horizontal scaling of 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request -## Thanks to related crates authors +## Acknowledgements I would like to thank the authors of the [Fang](https://github.com/ayrat555/fang) and [background_job](https://git.asonix.dog/asonix/background-jobs.git) crates which were the main inspiration for this project. diff --git a/src/queue.rs b/src/queue.rs index 94fa656..51813b7 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -8,14 +8,14 @@ use std::time::Duration; #[derive(Clone)] pub struct Queue where - S: TaskStore, + S: TaskStore + Clone, { task_store: Arc, } impl Queue where - S: TaskStore, + S: TaskStore + Clone, { pub fn new(task_store: Arc) -> Self { Queue { task_store } diff --git a/src/store.rs b/src/store.rs index 24637e3..1fd0b0b 100644 --- a/src/store.rs +++ b/src/store.rs @@ -197,7 +197,7 @@ pub mod test_store { } #[async_trait::async_trait] -pub trait TaskStore: Clone + Send + Sync + 'static { +pub trait TaskStore: Send + Sync + 'static { async fn pull_next_task( &self, queue_name: &str, @@ -213,3 +213,15 @@ pub trait TaskStore: Clone + Send + Sync + 'static { error: &str, ) -> Result; } + +#[cfg(test)] +mod tests { + use super::*; + use crate::store::test_store::MemoryTaskStore; + + #[test] + fn task_store_trait_is_object_safe() { + let store = MemoryTaskStore::default(); + let _object = &store as &dyn TaskStore; + } +} diff --git a/src/worker.rs b/src/worker.rs index a59bf44..ec827ec 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -55,7 +55,7 @@ where pub struct Worker where AppData: Clone + Send + 'static, - S: TaskStore, + S: TaskStore + Clone, { store: Arc, @@ -76,7 +76,7 @@ where impl Worker where AppData: Clone + Send + 'static, - S: TaskStore, + S: TaskStore + Clone, { pub(crate) fn new( store: Arc, diff --git a/src/worker_pool.rs b/src/worker_pool.rs index 3d8d0bc..f2c45b0 100644 --- a/src/worker_pool.rs +++ b/src/worker_pool.rs @@ -16,7 +16,7 @@ use tokio::task::JoinHandle; pub struct WorkerPool where AppData: Clone + Send + 'static, - S: TaskStore, + S: TaskStore + Clone, { /// Storage of tasks. task_store: Arc, @@ -44,7 +44,7 @@ where impl WorkerPool where AppData: Clone + Send + 'static, - S: TaskStore, + S: TaskStore + Clone, { /// Create a new worker pool. pub fn new(task_store: S, application_data_fn: A) -> Self