Constant bevy_cronjob::EVERY_5_SEC

source ·
pub const EVERY_5_SEC: &str = "0/5 * * * * * *";
Expand description

bevy_cronjob is a simple helper to run cronjobs (at repeated schedule) in Bevy.

§Usage

use std::time::Duration;
use bevy::{ MinimalPlugins};
use bevy::app::{App, PluginGroup, ScheduleRunnerPlugin, Update};
use bevy::log::{info, LogPlugin};

use bevy_ecs::prelude::{IntoSystemConfigs};
use bevy_cronjob::schedule_passed;

fn main() {
    App::new()
        .add_plugins(
            MinimalPlugins.set(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f64(
                1.0 / 60.0,
            ))),
        )
        .add_plugins(LogPlugin::default())
        .add_systems(Update, print_per_5_sec.run_if(schedule_passed("0/5 * * * * *")))
        .add_systems(Update, print_per_min.run_if(schedule_passed("0 * * * * *")))
        .add_systems(Update, print_per_hour.run_if(schedule_passed("0 0 * * * *")))
        .run()
}

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")
}

§Expression

the scheduling expression is base on cron

secminhourday of monthmonthday of weekyear
*******
0-590-590-231-231-121-71970-2100

Time is specified in UTC. Note that the year may be omitted.

Comma separated values such as 1,2,3 are allowed. For example, a schedule of 0,15,30,45 * * * * *’ would execute on every 15 seconds.

Ranges can be specified with a dash. For example 1-5 * * * * *’ would execute on every second for the first 5 seconds of a minute. run every 5 sec