Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #issule 37 & #issule 38 #39

Merged
merged 2 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "delay_timer"
version = "0.11.1"
version = "0.11.2"
authors = ["binchengZhao <binchengZhao@outlook.com>"]
edition = "2018"
repository = "https://github.com/BinChengZhao/delay-timer"
Expand Down Expand Up @@ -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"
Expand Down
17 changes: 10 additions & 7 deletions src/timer/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,17 @@ 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)) => {
if seconds == 0 {
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)
}
Expand All @@ -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)
}
};
Expand Down Expand Up @@ -1148,7 +1151,7 @@ mod tests {
.map(|i| {
debug_assert_eq!(
task.get_next_exec_timestamp().unwrap(),
timestamp() + (init_seconds * (i - 1))
timestamp() + (init_seconds * i)
);
})
.for_each(drop);
Expand Down Expand Up @@ -1180,7 +1183,7 @@ mod tests {
.map(|i| {
debug_assert_eq!(
task.get_next_exec_timestamp().unwrap(),
timestamp() + (init_minutes * (i - 1) * ONE_MINUTE)
timestamp() + (init_minutes * i * ONE_MINUTE)
);
})
.for_each(drop);
Expand All @@ -1201,7 +1204,7 @@ mod tests {
.map(|i| {
debug_assert_eq!(
task.get_next_exec_timestamp().unwrap(),
timestamp() + (init_hours * (i - 1) * ONE_HOUR)
timestamp() + (init_hours * i * ONE_HOUR)
);
})
.for_each(drop);
Expand All @@ -1222,7 +1225,7 @@ mod tests {
.map(|i| {
debug_assert_eq!(
task.get_next_exec_timestamp().unwrap(),
timestamp() + (init_days * (i - 1) * ONE_DAY)
timestamp() + (init_days * i * ONE_DAY)
);
})
.for_each(drop);
Expand Down
4 changes: 2 additions & 2 deletions src/timer/timer_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down