lholden / job_scheduler

A simple cron-like job scheduling library for Rust.
Apache License 2.0
196 stars 34 forks source link

* 0/2 * * * * * every two minutes seems to run every second #6

Closed glennpierce closed 6 years ago

glennpierce commented 6 years ago

I can't seem to get a task to run every two minutes. What am I doing wrong ?

Thanks

extern crate chrono; extern crate crossbeam; extern crate liblasso;

use std::time::Duration; use liblasso::job_scheduler::; use std::{thread, time}; use chrono::;

[test]

fn schedule_simple() {

let mut sched = JobScheduler::new();

sched.add(Job::new("* 0/2 * * * * *".parse().unwrap(), move || {
    println!("{}: Hello World (every 2 minutes)!", Utc::now());
}));

loop {
    sched.tick();
    //sched.tick_async();

    std::thread::sleep(Duration::from_millis(500));
}

}

lholden commented 6 years ago

@glennpierce Hi there! I believe the way you have your cron scheduled is that it will run every second for a minute every 2 minutes.

If you change that to "0 0/2 *" it will run once at the start of the minute every two minutes. I've tested this locally and it works for me. Please feel free to open up another ticket if you are still having issues. :)