From 739048b6670f88fb91cf2f7921ed6dfb2bb6d297 Mon Sep 17 00:00:00 2001 From: BinChengZhao Date: Mon, 9 May 2022 18:32:05 +0800 Subject: [PATCH] fix: issue #37 --- Cargo.toml | 4 ++-- src/timer/task.rs | 9 ++++++--- src/timer/timer_core.rs | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 76800c7..3114060 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "delay_timer" -version = "0.11.1" +version = "0.11.2" authors = ["binchengZhao "] edition = "2018" repository = "https://github.com/BinChengZhao/delay-timer" @@ -29,7 +29,7 @@ status-report = [] [dependencies] cron_clock = "0.8.0" anyhow = "^1.0.31" -rs-snowflake = "0.5.0" +rs-snowflake = "0.6.0" dashmap = "^4.0.2" lru = "^0.6.5" once_cell = "1.9.0" diff --git a/src/timer/task.rs b/src/timer/task.rs index 38a2b49..c28640a 100644 --- a/src/timer/task.rs +++ b/src/timer/task.rs @@ -228,7 +228,8 @@ impl<'a> TryFrom<(FrequencyUnify<'a>, ScheduleIteratorTimeZone)> for FrequencyIn return Err(FrequencyAnalyzeError::DisInitTime); } - let seconds_state: SecondsState = (timestamp()..).step_by(seconds as usize); + let seconds_state: SecondsState = + ((timestamp() + seconds)..).step_by(seconds as usize); FrequencyInner::SecondsCountDown(1, seconds_state) } FrequencyUnify::FrequencySeconds(FrequencySeconds::Repeated(seconds)) => { @@ -236,7 +237,8 @@ impl<'a> TryFrom<(FrequencyUnify<'a>, ScheduleIteratorTimeZone)> for FrequencyIn return Err(FrequencyAnalyzeError::DisInitTime); } - let seconds_state: SecondsState = (timestamp()..).step_by(seconds as usize); + let seconds_state: SecondsState = + ((timestamp() + seconds)..).step_by(seconds as usize); FrequencyInner::SecondsRepeated(seconds_state) } @@ -245,7 +247,8 @@ impl<'a> TryFrom<(FrequencyUnify<'a>, ScheduleIteratorTimeZone)> for FrequencyIn return Err(FrequencyAnalyzeError::DisInitTime); } - let seconds_state: SecondsState = (timestamp()..).step_by(seconds as usize); + let seconds_state: SecondsState = + ((timestamp() + seconds)..).step_by(seconds as usize); FrequencyInner::SecondsCountDown(count_down, seconds_state) } }; diff --git a/src/timer/timer_core.rs b/src/timer/timer_core.rs index efe932f..961d267 100644 --- a/src/timer/timer_core.rs +++ b/src/timer/timer_core.rs @@ -373,10 +373,10 @@ impl Timer { // when-on-slot61-exec: (task_excute_timestamp - timestamp + next_second_hand) % slot_seed == 61 // Time difference + next second hand % DEFAULT_TIMER_SLOT_COUNT - let step = task_excute_timestamp.checked_sub(timestamp).unwrap_or(1) + next_second_hand; + let step = task_excute_timestamp.checked_sub(timestamp).unwrap_or(1); let cylinder_line = step / DEFAULT_TIMER_SLOT_COUNT; task.set_cylinder_line(cylinder_line); - let slot_seed = step % DEFAULT_TIMER_SLOT_COUNT; + let slot_seed = (step + next_second_hand) % DEFAULT_TIMER_SLOT_COUNT; { let mut slot_mut = self