* 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
This commit is contained in:
parent
2bf660c9ee
commit
32b12182e0
4 changed files with 16 additions and 2 deletions
|
@ -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)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "fang"
|
||||
version = "0.7.1"
|
||||
version = "0.7.2"
|
||||
authors = ["Ayrat Badykov <ayratin555@gmail.com>" , "Pepe Márquez <pepe.marquezromero@gmail.com>"]
|
||||
description = "Background job processing library for Rust"
|
||||
repository = "https://github.com/ayrat555/fang"
|
||||
|
|
|
@ -150,6 +150,7 @@ pub trait AsyncQueueable: Send {
|
|||
timestamp: DateTime<Utc>,
|
||||
period: i32,
|
||||
) -> Result<PeriodicTask, AsyncQueueError>;
|
||||
|
||||
async fn schedule_next_task(
|
||||
&mut self,
|
||||
periodic_task: PeriodicTask,
|
||||
|
|
|
@ -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<AQueue> AsyncWorkerPool<AQueue>
|
||||
|
@ -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<Result<(), Error>> {
|
||||
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<AQueue> = AsyncWorker::builder()
|
||||
.queue(queue)
|
||||
.sleep_params(sleep_params)
|
||||
.retention_mode(retention_mode)
|
||||
.task_type(task_type)
|
||||
.build();
|
||||
|
||||
worker.run_tasks().await
|
||||
|
|
Loading…
Reference in a new issue