mirror of
https://git.asonix.dog/asonix/background-jobs.git
synced 2024-11-21 19:40:59 +00:00
Expose schedule in queuehandle, expose dev types in main lib
This commit is contained in:
parent
f8fa1bb5ef
commit
f1c4709e41
4 changed files with 31 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "background-jobs"
|
||||
description = "Background Jobs implemented with actix and futures"
|
||||
version = "0.8.0-alpha.1"
|
||||
version = "0.8.0-alpha.2"
|
||||
license-file = "LICENSE"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
repository = "https://git.asonix.dog/Aardwolf/background-jobs"
|
||||
|
@ -25,6 +25,6 @@ version = "0.8.0-alpha.0"
|
|||
path = "jobs-core"
|
||||
|
||||
[dependencies.background-jobs-actix]
|
||||
version = "0.8.0-alpha.0"
|
||||
version = "0.8.0-alpha.1"
|
||||
path = "jobs-actix"
|
||||
optional = true
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "background-jobs-actix"
|
||||
description = "in-process jobs processor based on Actix"
|
||||
version = "0.8.0-alpha.0"
|
||||
version = "0.8.0-alpha.1"
|
||||
license-file = "../LICENSE"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
repository = "https://git.asonix.dog/Aardwolf/background-jobs"
|
||||
|
|
|
@ -119,7 +119,8 @@
|
|||
|
||||
use actix::Arbiter;
|
||||
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 std::{collections::BTreeMap, sync::Arc, time::Duration};
|
||||
|
||||
|
@ -260,6 +261,24 @@ impl QueueHandle {
|
|||
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
|
||||
///
|
||||
/// This job will be added to it's queue on the server once every `Duration`. It will be
|
||||
|
|
|
@ -163,5 +163,13 @@
|
|||
|
||||
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")]
|
||||
pub use background_jobs_actix::{create_server, ActixJob, QueueHandle, WorkerConfig};
|
||||
|
|
Loading…
Reference in a new issue