From 32b12182e08885ab9f4999067ca10dc2dbeb5294 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 16 Aug 2022 13:25:19 +0300 Subject: [PATCH] Set task_type when starting a worker pool (#64) (#66) * Set task_type when starting a worker pool (#64) * make queue fields public * Set task_type when starting a worker pool * make fields private again * bump version --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- src/asynk/async_queue.rs | 1 + src/asynk/async_worker_pool.rs | 11 ++++++++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c2f5ce..3549e96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.7.2 (2022-08-16) + +- Set task_type when starting a worker pool - [#66](https://github.com/ayrat555/fang/pull/66) + ## 0.7.1 (2022-08-04) - Fix a conflict in exports of the `blocking` and the `asynk` features - [#61](https://github.com/ayrat555/fang/pull/61) diff --git a/Cargo.toml b/Cargo.toml index 73bbc34..c4913bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fang" -version = "0.7.1" +version = "0.7.2" authors = ["Ayrat Badykov " , "Pepe Márquez "] description = "Background job processing library for Rust" repository = "https://github.com/ayrat555/fang" diff --git a/src/asynk/async_queue.rs b/src/asynk/async_queue.rs index e698063..8ac2424 100644 --- a/src/asynk/async_queue.rs +++ b/src/asynk/async_queue.rs @@ -150,6 +150,7 @@ pub trait AsyncQueueable: Send { timestamp: DateTime, period: i32, ) -> Result; + async fn schedule_next_task( &mut self, periodic_task: PeriodicTask, diff --git a/src/asynk/async_worker_pool.rs b/src/asynk/async_worker_pool.rs index 6ed28bf..57796c4 100644 --- a/src/asynk/async_worker_pool.rs +++ b/src/asynk/async_worker_pool.rs @@ -1,4 +1,5 @@ use crate::asynk::async_queue::AsyncQueueable; +use crate::asynk::async_queue::DEFAULT_TASK_TYPE; use crate::asynk::async_worker::AsyncWorker; use crate::asynk::AsyncError as Error; use crate::{RetentionMode, SleepParams}; @@ -20,6 +21,8 @@ where pub retention_mode: RetentionMode, #[builder(setter(into))] pub number_of_workers: u32, + #[builder(default=DEFAULT_TASK_TYPE.to_string(), setter(into))] + pub task_type: String, } impl AsyncWorkerPool @@ -40,6 +43,7 @@ where pool.queue.clone(), pool.sleep_params.clone(), pool.retention_mode.clone(), + pool.task_type.clone(), ) .await; @@ -56,18 +60,23 @@ where queue: AQueue, sleep_params: SleepParams, retention_mode: RetentionMode, + task_type: String, ) -> JoinHandle> { - tokio::spawn(async move { Self::run_worker(queue, sleep_params, retention_mode).await }) + tokio::spawn(async move { + Self::run_worker(queue, sleep_params, retention_mode, task_type).await + }) } pub async fn run_worker( queue: AQueue, sleep_params: SleepParams, retention_mode: RetentionMode, + task_type: String, ) -> Result<(), Error> { let mut worker: AsyncWorker = AsyncWorker::builder() .queue(queue) .sleep_params(sleep_params) .retention_mode(retention_mode) + .task_type(task_type) .build(); worker.run_tasks().await