mirror of
https://git.asonix.dog/asonix/background-jobs.git
synced 2024-11-28 06:50:59 +00:00
actix-example: use sled storage
This commit is contained in:
parent
b5661fb8e6
commit
3607816bc5
2 changed files with 10 additions and 6 deletions
|
@ -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"
|
||||
|
|
|
@ -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(()))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue