dffee33b9c
* add uniq method for AsyncRunnable trait (#70) * add uniq method for asyncrunnable * add hash enum * remove string * return bool values * Task struct modified (#71) * Task struct modified * asynk module try to adapt new scheme * delete period in millis * delete period in millis completed * Cron support :D * Cron and single Schedule support :D * Current timestamp value * fix bug and new test that confirms that it was a bug * fix a call * Update Cargo.toml Co-authored-by: Ayrat Badykov <ayratin555@gmail.com> * comments suggestions * fix clippy * Better user api for schedule with cron * Cron tested with example * Comments adressed * Comments adressed Co-authored-by: Ayrat Badykov <ayratin555@gmail.com> Co-authored-by: Ayrat Badykov <ayratin555@gmail.com>
90 lines
1.8 KiB
Rust
90 lines
1.8 KiB
Rust
#![allow(clippy::extra_unused_lifetimes)]
|
|
|
|
use std::time::Duration;
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub enum RetentionMode {
|
|
KeepAll,
|
|
RemoveAll,
|
|
RemoveFinished,
|
|
}
|
|
impl Default for RetentionMode {
|
|
fn default() -> Self {
|
|
RetentionMode::RemoveAll
|
|
}
|
|
}
|
|
#[derive(Clone, Debug)]
|
|
pub struct SleepParams {
|
|
pub sleep_period: Duration,
|
|
pub max_sleep_period: Duration,
|
|
pub min_sleep_period: Duration,
|
|
pub sleep_step: Duration,
|
|
}
|
|
|
|
impl SleepParams {
|
|
pub fn maybe_reset_sleep_period(&mut self) {
|
|
if self.sleep_period != self.min_sleep_period {
|
|
self.sleep_period = self.min_sleep_period;
|
|
}
|
|
}
|
|
|
|
pub fn maybe_increase_sleep_period(&mut self) {
|
|
if self.sleep_period < self.max_sleep_period {
|
|
self.sleep_period += self.sleep_step;
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for SleepParams {
|
|
fn default() -> Self {
|
|
SleepParams {
|
|
sleep_period: Duration::from_secs(5),
|
|
max_sleep_period: Duration::from_secs(15),
|
|
min_sleep_period: Duration::from_secs(5),
|
|
sleep_step: Duration::from_secs(5),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[macro_use]
|
|
#[cfg(feature = "blocking")]
|
|
extern crate diesel;
|
|
|
|
#[doc(hidden)]
|
|
#[cfg(feature = "blocking")]
|
|
pub use diesel::pg::PgConnection;
|
|
|
|
#[doc(hidden)]
|
|
pub use typetag;
|
|
|
|
#[doc(hidden)]
|
|
pub extern crate serde;
|
|
|
|
#[doc(hidden)]
|
|
pub extern crate chrono;
|
|
|
|
#[doc(hidden)]
|
|
pub use serde_derive::{Deserialize, Serialize};
|
|
|
|
pub use chrono::DateTime;
|
|
pub use chrono::Utc;
|
|
pub use cron::Schedule;
|
|
|
|
#[cfg(feature = "blocking")]
|
|
pub mod blocking;
|
|
#[cfg(feature = "blocking")]
|
|
pub use blocking::*;
|
|
|
|
#[cfg(feature = "asynk")]
|
|
pub mod asynk;
|
|
|
|
#[cfg(feature = "asynk")]
|
|
pub use asynk::*;
|
|
|
|
#[cfg(feature = "asynk")]
|
|
#[doc(hidden)]
|
|
pub use bb8_postgres::tokio_postgres::tls::NoTls;
|
|
|
|
#[cfg(feature = "asynk")]
|
|
#[doc(hidden)]
|
|
pub use async_trait::async_trait;
|