10 releases (5 breaking)
Uses new Rust 2024
new 0.6.0 | Apr 25, 2025 |
---|---|
0.5.1 | Dec 9, 2024 |
0.5.0 | Nov 30, 2024 |
0.5.0-rc.1 | Oct 23, 2024 |
0.1.2 | Aug 7, 2023 |
#1599 in Game dev
66 downloads per month
21KB
122 lines
bevy_cronjob
bevy_cronjob
is a simple helper to run cronjob (at repeated schedule) in Bevy.
Usage
use bevy::log::LogPlugin;
use bevy::prelude::*;
use bevy_app::ScheduleRunnerPlugin;
use bevy_cronjob::prelude::*;
use std::time::Duration;
fn main() {
App::new()
.add_plugins(
MinimalPlugins.set(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f64(
1.0 / 60.0,
))),
)
.add_plugins(LogPlugin::default())
.add_plugins(CronJobPlugin)
.add_systems(Startup, setup)
.add_systems(
Update,
print_per_5_sec.run_if(schedule_passed("every 5 seconds")),
)
.add_systems(
Update,
print_per_min.run_if(schedule_passed("every 1 minute")),
)
.add_systems(Update, print_per_hour.run_if(schedule_passed("every hour")))
.run();
}
fn print_per_5_sec() {
info!("system run every 5 sec")
}
fn print_per_min() {
info!("system run every minute")
}
fn print_per_hour() {
info!("system run every hour")
}
fn setup(mut commands: Commands) {
commands
.spawn(ScheduleTimer::new("every 3 seconds"))
.observe(|_: Trigger<ScheduleArrived>| {
info!("3 seconds passed");
});
}
Expression
the scheduling expression is based 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.
Full List of Supported English Patterns
supported by english-to-cron
English Phrase | CronJob Syntax |
---|---|
every 15 seconds | 0/15 * * * * ? * |
run every minute | 0 * * * * ? * |
fire every day at 4:00 pm | 0 0 16 */1 * ? * |
at 10:00 am | 0 0 10 * * ? * |
run at midnight on the 1st and 15th of the month | 0 0 0 1,15 * ? * |
On Sunday at 12:00 | 0 0 12 ? * SUN * |
7pm every Thursday | 0 0 19 ? * THU * |
midnight on Tuesdays | 0 0 ? * TUE * |
Supported Versions
bevy | bevy_cronjob |
---|---|
0.16 | 0.6 |
0.15 | 0.5 |
0.14 | 0.4 |
0.13 | 0.3 |
0.12 | 0.2 |
0.11 | 0.1 |
License
Dual-licensed under either:
At your option. This means that when using this crate in your game, you may choose which license to use.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dually licensed as above, without any additional terms or conditions.
Dependencies
~15–22MB
~324K SLoC