Review Queue signature

This commit is contained in:
Rafael Caricio 2023-03-13 14:11:19 +01:00
parent 253a82fecf
commit 64e2315999
Signed by: rafaelcaricio
GPG key ID: 3C86DBCE8E93C947
4 changed files with 8 additions and 8 deletions

View file

@ -4,7 +4,6 @@ use backie::{PgTaskStore, Queue, WorkerPool};
use diesel_async::pg::AsyncPgConnection;
use diesel_async::pooled_connection::{bb8::Pool, AsyncDieselConnectionManager};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use std::time::Duration;
#[derive(Clone, Debug)]
@ -134,7 +133,7 @@ async fn main() {
let task2 = MyTask::new(20_000);
let task3 = MyFailingTask::new(50_000);
let queue = Queue::new(Arc::new(task_store)); // or use the `queue` instance returned by the worker pool
let queue = Queue::new(task_store); // or use the `queue` instance returned by the worker pool
queue.enqueue(task1).await.unwrap();
queue.enqueue(task2).await.unwrap();
queue.enqueue(task3).await.unwrap();

View file

@ -26,7 +26,7 @@ impl Default for RetentionMode {
pub use queue::Queue;
pub use runnable::BackgroundTask;
pub use store::{PgTaskStore, TaskStore};
pub use task::{CurrentTask, Task, TaskId, TaskState};
pub use task::{CurrentTask, NewTask, Task, TaskId, TaskState};
pub use worker::Worker;
pub use worker_pool::{QueueConfig, WorkerPool};

View file

@ -17,8 +17,10 @@ impl<S> Queue<S>
where
S: TaskStore + Clone,
{
pub fn new(task_store: Arc<S>) -> Self {
Queue { task_store }
pub fn new(task_store: S) -> Self {
Queue {
task_store: Arc::new(task_store),
}
}
pub async fn enqueue<BT>(&self, background_task: BT) -> Result<(), BackieError>

View file

@ -51,14 +51,13 @@ where
where
A: Fn(Queue<S>) -> AppData + Send + Sync + 'static,
{
let queue_store = Arc::new(task_store);
let queue = Queue::new(queue_store.clone());
let queue = Queue::new(task_store.clone());
let application_data_fn = {
let queue = queue.clone();
move || application_data_fn(queue.clone())
};
Self {
task_store: queue_store,
task_store: Arc::new(task_store),
queue,
application_data_fn: Arc::new(application_data_fn),
task_registry: BTreeMap::new(),