agilord / cron

A cron-like time-based job scheduler for Dart
BSD 3-Clause "New" or "Revised" License
116 stars 23 forks source link

add seconds #11

Closed Hong1008 closed 3 years ago

Hong1008 commented 3 years ago

When the CRON expression is a string comprising 6 fields, there is a seconds field at the beginning of the pattern. Cron().schedule(Schedule.parse('* * * * * *'), () async { print('every seconds'); });

isoos commented 3 years ago

I don't mind having the seconds there, however, I haven't seen this in any cron system (yet). Do you have a reference/specification that uses it? (I also thought that the 6th parameter could be a year - although that makes little practical use...)

Hong1008 commented 3 years ago

I don't mind having the seconds there, however, I haven't seen this in any cron system (yet). Do you have a reference/specification that uses it? (I also thought that the 6th parameter could be a year - although that makes little practical use...)

see: https://en.wikipedia.org/wiki/Cron#Overview There's a phrase like this. "In some uses of the CRON format there is also a seconds field at the beginning of the pattern. In that case, the CRON expression is a string comprising 6 or 7 fields." I have to synchronize data every 30 seconds without use Timer in dart, because I want to synchronize on time

Hong1008 commented 3 years ago

Well, I've solved my problem now like this.

Timer.periodic(Duration(seconds: 1), (timer) {
      var seconds = DateTime.now().second;
      if(seconds == 0 || seconds == 30){
        //do job
      }
});

You don't have to take this PR if you don't want to.

isoos commented 3 years ago

I'll add some tests tomorrow and will publish it after that.

isoos commented 3 years ago

FYI: I've updated some parts, fixed a small issue, and published.