From 6cec89361c7f855171ddc64daf394d692bd68ea7 Mon Sep 17 00:00:00 2001 From: asonix Date: Sun, 7 Jan 2024 22:48:38 -0600 Subject: [PATCH] Update examples to use new api --- examples/basic-example/src/main.rs | 22 +++++++++++----------- examples/long-example/src/main.rs | 4 +++- examples/managed-example/src/main.rs | 4 +++- examples/metrics-example/src/main.rs | 6 ++++-- examples/panic-example/src/main.rs | 2 +- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/examples/basic-example/src/main.rs b/examples/basic-example/src/main.rs index a3c37f8..9849737 100644 --- a/examples/basic-example/src/main.rs +++ b/examples/basic-example/src/main.rs @@ -1,12 +1,10 @@ use actix_rt::Arbiter; use anyhow::Error; use background_jobs::{ - // memory_storage::{ActixTimer, Storage}, - ActixJob as Job, - MaxRetries, - WorkerConfig, + memory_storage::{ActixTimer, Storage}, + ActixSpawner, MaxRetries, UnsendJob as Job, WorkerConfig, }; -use background_jobs_sled_storage::Storage; +// use background_jobs_sled_storage::Storage; use std::{ future::{ready, Ready}, time::{Duration, SystemTime}, @@ -36,9 +34,8 @@ async fn main() -> Result<(), Error> { .init(); // Set up our Storage - let db = sled::Config::new().temporary(true).open()?; - let storage = Storage::new(db)?; - // let storage = Storage::new(ActixTimer); + // let db = sled::Config::new().temporary(true).open()?; + let storage = Storage::new(ActixTimer); let arbiter = Arbiter::new(); @@ -53,9 +50,11 @@ async fn main() -> Result<(), Error> { queue_handle.queue(MyJob::new(1, 2)).await?; queue_handle.queue(MyJob::new(3, 4)).await?; queue_handle.queue(MyJob::new(5, 6)).await?; - queue_handle - .schedule(MyJob::new(7, 8), SystemTime::now() + Duration::from_secs(2)) - .await?; + for i in 0..20 { + queue_handle + .schedule(MyJob::new(7, 8), SystemTime::now() + Duration::from_secs(i)) + .await?; + } // Block on Actix actix_rt::signal::ctrl_c().await?; @@ -86,6 +85,7 @@ impl MyJob { impl Job for MyJob { type State = MyState; type Future = Ready>; + type Spawner = ActixSpawner; // The name of the job. It is super important that each job has a unique name, // because otherwise one job will overwrite another job when they're being diff --git a/examples/long-example/src/main.rs b/examples/long-example/src/main.rs index 2545421..2066f18 100644 --- a/examples/long-example/src/main.rs +++ b/examples/long-example/src/main.rs @@ -1,6 +1,6 @@ use actix_rt::Arbiter; use anyhow::Error; -use background_jobs::{ActixJob as Job, MaxRetries, WorkerConfig}; +use background_jobs::{ActixSpawner, MaxRetries, UnsendJob as Job, WorkerConfig}; use background_jobs_sled_storage::Storage; use std::{ future::{ready, Future, Ready}, @@ -88,6 +88,7 @@ impl MyJob { impl Job for MyJob { type State = MyState; type Future = Ready>; + type Spawner = ActixSpawner; // The name of the job. It is super important that each job has a unique name, // because otherwise one job will overwrite another job when they're being @@ -117,6 +118,7 @@ impl Job for MyJob { impl Job for LongJob { type State = MyState; type Future = Pin>>>; + type Spawner = ActixSpawner; const NAME: &'static str = "LongJob"; diff --git a/examples/managed-example/src/main.rs b/examples/managed-example/src/main.rs index 3a0585f..e5a8736 100644 --- a/examples/managed-example/src/main.rs +++ b/examples/managed-example/src/main.rs @@ -1,6 +1,6 @@ use actix_rt::Arbiter; use anyhow::Error; -use background_jobs::{ActixJob as Job, MaxRetries, WorkerConfig}; +use background_jobs::{ActixSpawner, MaxRetries, UnsendJob as Job, WorkerConfig}; use background_jobs_sled_storage::Storage; use std::{ future::{ready, Ready}, @@ -100,6 +100,7 @@ impl MyJob { impl Job for MyJob { type State = MyState; type Future = Ready>; + type Spawner = ActixSpawner; // The name of the job. It is super important that each job has a unique name, // because otherwise one job will overwrite another job when they're being @@ -129,6 +130,7 @@ impl Job for MyJob { impl Job for StopJob { type State = MyState; type Future = Ready>; + type Spawner = ActixSpawner; const NAME: &'static str = "StopJob"; const QUEUE: &'static str = DEFAULT_QUEUE; diff --git a/examples/metrics-example/src/main.rs b/examples/metrics-example/src/main.rs index 84b025c..c36e48c 100644 --- a/examples/metrics-example/src/main.rs +++ b/examples/metrics-example/src/main.rs @@ -1,9 +1,10 @@ use actix_rt::Arbiter; use anyhow::Error; use background_jobs::{ - // memory_storage::{ActixTimer, Storage}, - ActixJob as Job, + ActixSpawner, MaxRetries, + // memory_storage::{ActixTimer, Storage}, + UnsendJob as Job, WorkerConfig, }; use background_jobs_sled_storage::Storage; @@ -91,6 +92,7 @@ impl MyJob { impl Job for MyJob { type State = MyState; type Future = Pin> + 'static>>; + type Spawner = ActixSpawner; // The name of the job. It is super important that each job has a unique name, // because otherwise one job will overwrite another job when they're being diff --git a/examples/panic-example/src/main.rs b/examples/panic-example/src/main.rs index 58b53a3..ab73d6e 100644 --- a/examples/panic-example/src/main.rs +++ b/examples/panic-example/src/main.rs @@ -1,6 +1,6 @@ use actix_rt::Arbiter; use anyhow::Error; -use background_jobs::{ActixJob as Job, MaxRetries, WorkerConfig}; +use background_jobs::{Job, MaxRetries, WorkerConfig}; use background_jobs_sled_storage::Storage; use std::{ future::{ready, Ready},