mirror of
https://git.asonix.dog/asonix/background-jobs.git
synced 2024-11-21 19:40:59 +00:00
Make example wait so it can process before getting the shutdown signal
This commit is contained in:
parent
a142eb2d3f
commit
ba758b19ab
1 changed files with 66 additions and 34 deletions
|
@ -1,6 +1,8 @@
|
|||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use failure::Error;
|
||||
use futures::{
|
||||
future::{lazy, IntoFuture},
|
||||
|
@ -42,8 +44,9 @@ fn main() {
|
|||
dotenv::dotenv().ok();
|
||||
env_logger::init();
|
||||
|
||||
tokio::run(lazy(|| {
|
||||
let mut runner = JobRunner::new(1234, 8, "example-db");
|
||||
tokio::run(
|
||||
lazy(|| {
|
||||
let mut runner = JobRunner::new(1234, 4, "example-db");
|
||||
runner.register_processor(MyProcessor);
|
||||
|
||||
let handle = runner.spawn();
|
||||
|
@ -65,6 +68,26 @@ fn main() {
|
|||
some_usize: 8,
|
||||
other_usize: 13,
|
||||
},
|
||||
MyJobArguments {
|
||||
some_usize: 21,
|
||||
other_usize: 34,
|
||||
},
|
||||
MyJobArguments {
|
||||
some_usize: 55,
|
||||
other_usize: 89,
|
||||
},
|
||||
MyJobArguments {
|
||||
some_usize: 144,
|
||||
other_usize: 233,
|
||||
},
|
||||
MyJobArguments {
|
||||
some_usize: 377,
|
||||
other_usize: 610,
|
||||
},
|
||||
MyJobArguments {
|
||||
some_usize: 987,
|
||||
other_usize: 1597,
|
||||
},
|
||||
];
|
||||
|
||||
let _: Vec<_> = jobs
|
||||
|
@ -78,6 +101,15 @@ fn main() {
|
|||
})
|
||||
.collect();
|
||||
|
||||
Ok(())
|
||||
}));
|
||||
Ok(handle)
|
||||
})
|
||||
.and_then(|handle| {
|
||||
tokio::timer::Delay::new(tokio::clock::now() + Duration::from_secs(2))
|
||||
.map(move |_| {
|
||||
let _ = handle;
|
||||
()
|
||||
})
|
||||
.map_err(|_| ())
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue