Skip to content

Commit

Permalink
Refactor scheduler service by removing redundant next_run function
Browse files Browse the repository at this point in the history
  • Loading branch information
slackspace-io committed Apr 14, 2024
1 parent 1c46949 commit 9b0b117
Showing 1 changed file with 0 additions and 26 deletions.
26 changes: 0 additions & 26 deletions src/services/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,13 @@ use std::str::FromStr;
use std::time::Duration;
use tokio::time::{sleep_until, Instant as TokioInstant};

#[cfg(feature = "server")]
pub async fn next_run(schedule: Schedule) {
// Example cron schedule: Every minute
//print next 5 scheduled times
let mut i = 0;
for datetime in schedule.upcoming(chrono::Utc) {
if i < 5 {
println!("Next scheduled time: {}", datetime);
i += 1;
} else {
break;
}
}
let now = chrono::Utc::now();
if let Some(next) = schedule.upcoming(chrono::Utc).next() {
let duration_until_next = (next - now).to_std().expect("Failed to calculate duration");
println!("Next scheduled time: {:?}", next);
// Convert std::time::Instant to tokio::time::Instant
refresh_all_workloads().await;
}
}


#[cfg(feature = "server")]
pub async fn scheduler(schedule: &Schedule) {
// Example cron schedule: Every minute
log::info!("Scheduler started");
//let schedule_str = "0 * * * * *"; // Adjust the cron expression as needed
//let schedule = Schedule::from_str(schedule_str).expect("Failed to parse cron expression");
println!("Cron schedule: {}", schedule);
log::info!("Cron schedule: {}", schedule);
// Find the next scheduled time
//print next 5 scheduled times
let mut i = 0;
for datetime in schedule.upcoming(chrono::Utc) {
if i < 5 {
Expand Down

0 comments on commit 9b0b117

Please sign in to comment.