From 3607816bc53b99945750705cfcca0519bc6746f3 Mon Sep 17 00:00:00 2001 From: asonix Date: Thu, 4 Feb 2021 12:40:39 -0600 Subject: [PATCH] actix-example: use sled storage --- examples/actix-example/Cargo.toml | 4 +++- examples/actix-example/src/main.rs | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/actix-example/Cargo.toml b/examples/actix-example/Cargo.toml index aa5e9df..4fb51c8 100644 --- a/examples/actix-example/Cargo.toml +++ b/examples/actix-example/Cargo.toml @@ -11,6 +11,8 @@ actix-rt = "2.0.0" anyhow = "1.0" async-trait = "0.1.24" background-jobs = { version = "0.9.0", path = "../.." } +background-jobs-sled-storage = { version = "0.9.0", path = "../../jobs-sled" } +chrono = "0.4" env_logger = "0.7" -futures = "0.3" serde = { version = "1.0", features = ["derive"] } +sled = "0.34" diff --git a/examples/actix-example/src/main.rs b/examples/actix-example/src/main.rs index d2b542b..e33802e 100644 --- a/examples/actix-example/src/main.rs +++ b/examples/actix-example/src/main.rs @@ -1,6 +1,8 @@ use anyhow::Error; use background_jobs::{create_server, Job, MaxRetries, WorkerConfig}; -use futures::future::{ok, Ready}; +use background_jobs_sled_storage::Storage; +use chrono::{Duration, Utc}; +use std::future::{ready, Ready}; const DEFAULT_QUEUE: &str = "default"; @@ -19,9 +21,8 @@ pub struct MyJob { async fn main() -> Result<(), Error> { env_logger::init(); // Set up our Storage - // For this example, we use the default in-memory storage mechanism - use background_jobs::memory_storage::Storage; - let storage = Storage::new(); + let db = sled::Config::new().temporary(true).open()?; + let storage = Storage::new(db)?; // Start the application server. This guards access to to the jobs store let queue_handle = create_server(storage); @@ -36,6 +37,7 @@ async fn main() -> Result<(), Error> { queue_handle.queue(MyJob::new(1, 2))?; queue_handle.queue(MyJob::new(3, 4))?; queue_handle.queue(MyJob::new(5, 6))?; + queue_handle.schedule(MyJob::new(7, 8), Utc::now() + Duration::seconds(2))?; // Block on Actix actix_rt::signal::ctrl_c().await?; @@ -85,6 +87,6 @@ impl Job for MyJob { fn run(self, state: MyState) -> Self::Future { println!("{}: args, {:?}", state.app_name, self); - ok(()) + ready(Ok(())) } }