Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
720ee972f8 | |||
991fd5dd83
|
|||
84820dcc82
|
|||
55498adffd
|
|||
08145eed13 | |||
fb4bd51d71 | |||
|
3a3af4757c | ||
69c8b7409b
|
|||
85b6079b60
|
|||
989f073061
|
17
CHANGELOG.md
17
CHANGELOG.md
@@ -6,6 +6,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [0.3.0] - 2024-12-13
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- allow job to start immediately
|
||||||
|
- rename and publish
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- test can now run at least 2 times, initial and then via. delay
|
||||||
|
- with child token as well
|
||||||
|
|
||||||
|
## [0.2.0] - 2024-08-02
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- use actual delimination
|
||||||
|
- use source instead
|
||||||
|
- add inner error
|
||||||
|
|
||||||
## [0.1.0] - 2024-08-02
|
## [0.1.0] - 2024-08-02
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
28
Cargo.lock
generated
28
Cargo.lock
generated
@@ -1,6 +1,6 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aho-corasick"
|
name = "aho-corasick"
|
||||||
@@ -52,19 +52,6 @@ version = "1.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "drift"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"anyhow",
|
|
||||||
"async-trait",
|
|
||||||
"thiserror",
|
|
||||||
"tokio",
|
|
||||||
"tokio-util",
|
|
||||||
"tracing",
|
|
||||||
"tracing-test",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-core"
|
name = "futures-core"
|
||||||
version = "0.3.30"
|
version = "0.3.30"
|
||||||
@@ -140,6 +127,19 @@ dependencies = [
|
|||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nodrift"
|
||||||
|
version = "0.2.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"async-trait",
|
||||||
|
"thiserror",
|
||||||
|
"tokio",
|
||||||
|
"tokio-util",
|
||||||
|
"tracing",
|
||||||
|
"tracing-test",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nu-ansi-term"
|
name = "nu-ansi-term"
|
||||||
version = "0.46.0"
|
version = "0.46.0"
|
||||||
|
@@ -3,7 +3,7 @@ members = ["crates/*"]
|
|||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.1.0"
|
version = "0.3.0"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
drift = { path = "crates/drift" }
|
drift = { path = "crates/drift" }
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "drift"
|
name = "nodrift"
|
||||||
version.workspace = true
|
version.workspace = true
|
||||||
|
description = "no Drift is an application for scheduling recurring jobs"
|
||||||
|
license = "MIT"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@@ -5,8 +5,11 @@ use std::future::Future;
|
|||||||
use tokio::time;
|
use tokio::time;
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
|
|
||||||
#[derive(Debug, Clone, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum DriftError {}
|
pub enum DriftError {
|
||||||
|
#[error("job failed with inner error: {0}")]
|
||||||
|
JobError(#[source] anyhow::Error),
|
||||||
|
}
|
||||||
|
|
||||||
pub fn schedule<F, Fut>(interval: Duration, func: F) -> CancellationToken
|
pub fn schedule<F, Fut>(interval: Duration, func: F) -> CancellationToken
|
||||||
where
|
where
|
||||||
@@ -31,6 +34,22 @@ where
|
|||||||
|
|
||||||
async move {
|
async move {
|
||||||
let mut wait = interval;
|
let mut wait = interval;
|
||||||
|
let start = std::time::Instant::now();
|
||||||
|
|
||||||
|
tracing::debug!("running job");
|
||||||
|
let child_token = cancellation_token.child_token();
|
||||||
|
if let Err(e) = drifter.execute(child_token).await {
|
||||||
|
tracing::error!("drift job failed with error: {}, stopping routine", e);
|
||||||
|
cancellation_token.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
let elapsed = start.elapsed();
|
||||||
|
wait = interval.saturating_sub(elapsed);
|
||||||
|
tracing::debug!(
|
||||||
|
"job took: {}ms, waiting: {}ms for next run",
|
||||||
|
elapsed.as_millis(),
|
||||||
|
wait.as_millis()
|
||||||
|
);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let child_token = cancellation_token.child_token();
|
let child_token = cancellation_token.child_token();
|
||||||
@@ -184,7 +203,7 @@ mod tests {
|
|||||||
assert!(token.is_cancelled());
|
assert!(token.is_cancelled());
|
||||||
|
|
||||||
let counter = drifter.counter.lock().unwrap();
|
let counter = drifter.counter.lock().unwrap();
|
||||||
assert_eq!(*counter, 1);
|
assert_eq!(*counter, 2);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user