Filter by job-readiness as well

This commit is contained in:
asonix 2019-05-25 18:09:10 -05:00
parent 0a509e0271
commit dfba0cf7f2
2 changed files with 6 additions and 1 deletions

View file

@ -1,7 +1,7 @@
[package] [package]
name = "background-jobs-sled-storage" name = "background-jobs-sled-storage"
description = "Sled storage backend for background-jobs" description = "Sled storage backend for background-jobs"
version = "0.1.1" version = "0.1.2"
license = "GPL-3.0" license = "GPL-3.0"
authors = ["asonix <asonix@asonix.dog>"] authors = ["asonix <asonix@asonix.dog>"]
repository = "https://git.asonix.dog/Aardwolf/background-jobs" repository = "https://git.asonix.dog/Aardwolf/background-jobs"
@ -12,6 +12,7 @@ edition = "2018"
[dependencies] [dependencies]
background-jobs-core = { version = "0.5", path = "../jobs-core" } background-jobs-core = { version = "0.5", path = "../jobs-core" }
chrono = "0.4"
failure = "0.1" failure = "0.1"
sled = "0.24" sled = "0.24"
serde = "1.0" serde = "1.0"

View file

@ -1,4 +1,5 @@
use background_jobs_core::{JobInfo, Storage, Stats}; use background_jobs_core::{JobInfo, Storage, Stats};
use chrono::offset::Utc;
mod error; mod error;
mod sled_wrappers; mod sled_wrappers;
@ -41,12 +42,15 @@ impl Storage for SledStorage {
let job_tree = self.jobinfo.clone(); let job_tree = self.jobinfo.clone();
self.lock_queue(queue, move || { self.lock_queue(queue, move || {
let now = Utc::now();
let job = queue_tree let job = queue_tree
.iter() .iter()
.filter_map(|res| res.ok()) .filter_map(|res| res.ok())
.filter_map(|(id, in_queue)| if queue == in_queue { Some(id) } else { None }) .filter_map(|(id, in_queue)| if queue == in_queue { Some(id) } else { None })
.filter_map(|id| job_tree.get(id).ok()) .filter_map(|id| job_tree.get(id).ok())
.filter_map(|opt| opt) .filter_map(|opt| opt)
.filter(|job| job.is_ready(now))
.next(); .next();
if let Some(ref job) = job { if let Some(ref job) = job {