From fd03e92ac63a5d255064b220f69b66c15b949870 Mon Sep 17 00:00:00 2001 From: Ioannis Vogiatzis Date: Mon, 26 Oct 2026 12:02:07 +0100 Subject: [PATCH] fix: schedule in local time with cron's DST fix Go back to scheduling in the system's local time and use cron from git at cf2dc1d5, which includes zslayton/cron#145. The released 0.16.0 and 0.17.0 can hang when the clocks go back. Switch back to a crates.io release once one includes the fix. --- Cargo.lock | 5 ++--- Cargo.toml | 3 ++- README.md | 2 -- src/main.rs | 10 +++++----- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6fe27b0..7a23470 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,9 +58,8 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cron" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "089df96cf6a25253b4b6b6744d86f91150a3d4df546f31a95def47976b8cba97" +version = "0.17.0" +source = "git+https://github.com/zslayton/cron?rev=cf2dc1d519246de9ad230d33de2b7cd65e30305e#cf2dc1d519246de9ad230d33de2b7cd65e30305e" dependencies = [ "chrono", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index 910c41d..70019b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,5 @@ repository = "https://github.com/stephank/pocketcron" [dependencies] chrono = { version = "0.4.26", default-features = false, features = ["clock"] } -cron = "0.16.0" +# Unreleased fix for the DST fall-back hang (zslayton/cron#145). Switch back to a crates.io release once one includes it. +cron = { git = "https://github.com/zslayton/cron", rev = "cf2dc1d519246de9ad230d33de2b7cd65e30305e" } diff --git a/README.md b/README.md index 3e5610c..b1c3f68 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,4 @@ A tiny cronjob runner. Great as a 'sidecar' process in your application. - Supports only the user crontab format. (No username field, like in system crontab files.) -- Schedules are always in UTC, regardless of the system time zone. - - Not a deamon. Always runs in the foreground. diff --git a/src/main.rs b/src/main.rs index 12f1a62..6f7273b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use std::{ thread, }; -use chrono::{DateTime, Duration, Utc}; +use chrono::{DateTime, Duration, offset::Local}; use cron::OwnedScheduleIterator; /// Description and state of a job. @@ -15,9 +15,9 @@ struct Job { /// Job index, used as identifier for logging. id: usize, /// Schedule iterator. - upcoming: OwnedScheduleIterator, + upcoming: OwnedScheduleIterator, /// Next time this job will run. - next: Option>, + next: Option>, /// Shell command. command: String, /// Whether the process is running. @@ -40,7 +40,7 @@ fn main() { } loop { - let now = Utc::now(); + let now = Local::now(); // Find the minimum of all jobs' `next` time. // Max sleep is 1 minute, to account for any clock jumps. @@ -88,7 +88,7 @@ fn load_jobs(jobs: &mut Vec, path: OsString) { }; // Read by line. - let now = Utc::now(); + let now = Local::now(); for (line_no, line) in BufReader::new(file).lines().enumerate() { let line = match line { Ok(line) => line,