Expose schedule in queuehandle, expose dev types in main lib

This commit is contained in:
asonix 2020-04-21 12:04:18 -05:00
parent f8fa1bb5ef
commit f1c4709e41
4 changed files with 31 additions and 4 deletions

View file

@ -1,7 +1,7 @@
[package] [package]
name = "background-jobs" name = "background-jobs"
description = "Background Jobs implemented with actix and futures" description = "Background Jobs implemented with actix and futures"
version = "0.8.0-alpha.1" version = "0.8.0-alpha.2"
license-file = "LICENSE" license-file = "LICENSE"
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"
@ -25,6 +25,6 @@ version = "0.8.0-alpha.0"
path = "jobs-core" path = "jobs-core"
[dependencies.background-jobs-actix] [dependencies.background-jobs-actix]
version = "0.8.0-alpha.0" version = "0.8.0-alpha.1"
path = "jobs-actix" path = "jobs-actix"
optional = true optional = true

View file

@ -1,7 +1,7 @@
[package] [package]
name = "background-jobs-actix" name = "background-jobs-actix"
description = "in-process jobs processor based on Actix" description = "in-process jobs processor based on Actix"
version = "0.8.0-alpha.0" version = "0.8.0-alpha.1"
license-file = "../LICENSE" license-file = "../LICENSE"
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"

View file

@ -119,7 +119,8 @@
use actix::Arbiter; use actix::Arbiter;
use anyhow::Error; use anyhow::Error;
use background_jobs_core::{new_job, Job, ProcessorMap, Stats, Storage}; use background_jobs_core::{new_job, new_scheduled_job, Job, ProcessorMap, Stats, Storage};
use chrono::{DateTime, Utc};
use log::error; use log::error;
use std::{collections::BTreeMap, sync::Arc, time::Duration}; use std::{collections::BTreeMap, sync::Arc, time::Duration};
@ -260,6 +261,24 @@ impl QueueHandle {
Ok(()) Ok(())
} }
/// Schedule a job for execution later
///
/// This job will be sent to the server for storage, and will execute after the specified time
/// and when a worker for the job's queue is free to do so.
pub fn schedule<J>(&self, job: J, after: DateTime<Utc>) -> Result<(), Error>
where
J: Job,
{
let job = new_scheduled_job(job, after)?;
let server = self.inner.clone();
actix::spawn(async move {
if let Err(e) = server.new_job(job).await {
error!("Error creating job, {}", e);
}
});
Ok(())
}
/// Queues a job for recurring execution /// Queues a job for recurring execution
/// ///
/// This job will be added to it's queue on the server once every `Duration`. It will be /// This job will be added to it's queue on the server once every `Duration`. It will be

View file

@ -163,5 +163,13 @@
pub use background_jobs_core::{memory_storage, Backoff, Job, JobStat, MaxRetries, Stats}; pub use background_jobs_core::{memory_storage, Backoff, Job, JobStat, MaxRetries, Stats};
pub mod dev {
//! Useful types and methods for developing Storage and Processor implementations.
pub use background_jobs_core::{
new_job, new_scheduled_job, process, CachedProcessorMap, JobInfo, NewJobInfo, ProcessorMap,
ReturnJobInfo, Storage,
};
}
#[cfg(feature = "background-jobs-actix")] #[cfg(feature = "background-jobs-actix")]
pub use background_jobs_actix::{create_server, ActixJob, QueueHandle, WorkerConfig}; pub use background_jobs_actix::{create_server, ActixJob, QueueHandle, WorkerConfig};