Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
foxzool committed Dec 1, 2023
1 parent 1394f79 commit 349c5ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
15 changes: 10 additions & 5 deletions examples/cronjobs.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::time::Duration;
use bevy::{ MinimalPlugins};

use bevy::app::{App, PluginGroup, ScheduleRunnerPlugin, Update};
use bevy::log::{info, LogPlugin};
use bevy::MinimalPlugins;
use bevy_ecs::prelude::IntoSystemConfigs;

use bevy_ecs::prelude::{IntoSystemConfigs};
use bevy_cronjob::{EVERY_HOUR, EVERY_MIN, schedule_passed};
use bevy_cronjob::{schedule_passed, EVERY_HOUR, EVERY_MIN};

fn main() {
App::new()
Expand All @@ -14,7 +15,10 @@ fn main() {
))),
)
.add_plugins(LogPlugin::default())
.add_systems(Update, print_per_5_sec.run_if(schedule_passed("0/5 * * * * *")))
.add_systems(
Update,
print_per_5_sec.run_if(schedule_passed("0/5 * * * * *")),
)
.add_systems(Update, print_per_min.run_if(schedule_passed(EVERY_MIN)))
.add_systems(Update, print_per_hour.run_if(schedule_passed(EVERY_HOUR)))
.run()
Expand All @@ -23,10 +27,11 @@ fn main() {
fn print_per_5_sec() {
info!("print every 5 sec")
}

fn print_per_min() {
info!("print every minute")
}

fn print_per_hour() {
info!("print every hour")
}

7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ pub const EVERY_HOUR: &str = "0 0 * * * * *";
/// run every day
pub const EVERY_DAY: &str = "0 0 0 * * * *";


/// Creates a closure that checks if the cron expression has passed
/// # expression format:
/// Note that the year may be omitted.
Expand All @@ -93,7 +92,9 @@ pub const EVERY_DAY: &str = "0 0 0 * * * *";
/// |0 * * * * * | every minute |
/// |0 5,10 * * * * | every hour on 5 and 10 min|
/// |0 0 1 * * * | every day on 1:00:00|
pub fn schedule_passed(expression: &str) -> impl FnMut(Local<Option<DateTime<chrono::Utc>>>) -> bool {
pub fn schedule_passed(
expression: &str,
) -> impl FnMut(Local<Option<DateTime<chrono::Utc>>>) -> bool {
let schedule = Schedule::from_str(expression).expect("Failed to parse cron expression");
move |mut local_schedule: Local<Option<DateTime<chrono::Utc>>>| {
if let Some(datetime) = schedule.upcoming(chrono::Utc).next() {
Expand All @@ -112,4 +113,4 @@ pub fn schedule_passed(expression: &str) -> impl FnMut(Local<Option<DateTime<chr

false
}
}
}

0 comments on commit 349c5ed

Please sign in to comment.