#cron #bevy #cron-expression #plugin #bevy-ecs

bevy_cronjob

A simple helper to run cronjobs (at repeated schedule) in Bevy

5 unstable releases

0.3.0 Feb 18, 2024
0.2.0 Nov 6, 2023
0.1.2 Aug 7, 2023
0.1.1 Aug 2, 2023
0.1.0 Aug 2, 2023

#976 in Game dev

Download history 122/week @ 2024-02-13 39/week @ 2024-02-20 16/week @ 2024-02-27 1/week @ 2024-03-05 6/week @ 2024-03-12 5/week @ 2024-03-26 51/week @ 2024-04-02

56 downloads per month

MIT/Apache

18KB

crates.io MIT/Apache 2.0 crates.io CI Documentation

bevy_cronjob

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

sec min hour day of month month day of week year
* * * * * * *
0-59 0-59 0-23 1-23 1-12 1-7 1970-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.

Supported Versions

bevy bevy_cronjob
0.12 0.2
0.11 0.1

License

Dual-licensed under either

  • MIT
  • Apache 2.0

Dependencies

~10–19MB
~228K SLoC