floraison / fugit

time tools (cron, parsing, durations, ...) for Ruby, rufus-scheduler, and flor
MIT License
357 stars 30 forks source link

Scheduling on tuesday every other week #1

Closed jmettraux closed 5 years ago

jmettraux commented 6 years ago

Seen first on https://github.com/jmettraux/rufus-scheduler/issues/259

    "0 0 * * tue/2"    #~~> every second tuesday at midnight
    "0 0 * * tue/2+1"  #~~> every odd second tuesday at midnight

Eventutally generalize the /n+m concept to the already existing /n systems.

jmettraux commented 6 years ago

Eventutally generalize the /n+m concept to the already existing /n systems.

Days (Monday, Tuesday, Wednesday, ...) are not numbers like days (1..31) or hours (0..24). That generalization is not possible.

jmettraux commented 6 years ago

Rather "0 0 * * tue%2" or "0 0 * * tue%2+1"

jmettraux commented 6 years ago

0 22 * * Tue%2 is nice, but when is the "not other Tuesday"? What is the point of reference? "Oh it's the next Tuesday from the start of the schedule", OK, but the scheduler might restart that reference point will change.

We could use the "last_time" in the job, might work, but that implies passing some context to the #match? method of the Fugit::Cron.

jmettraux commented 6 years ago

Use the next_time(start_time)'s start_time. When it's a Tuesday, it's the other Tuesday else it's next Tuesday.

thisismydesign commented 5 years ago

Is there a workaround for this currently available?

jmettraux commented 5 years ago

Hello @thisismydesign,

this issue is about extending the cron syntax supported by fugit.

For when do you need that? In what context are you using fugit?

thisismydesign commented 5 years ago

Hey @jmettraux,

My use case is bi-weekly dynamic scheduling with resque-scheduler.

resque-scheduler uses rufus-scheduler, which uses fugit if my understanding is correct. Got here by the issue you referenced above: https://github.com/jmettraux/rufus-scheduler/issues/259

Our timeframe for this is pretty short but I'd be happy to come back and use this feature when available.

jmettraux commented 5 years ago

@thisismydesign,

you can easily implement it by yourself in your Resque-Scheduler job implementation, skip the job if its last trigger time was less than 13 days ago.

I'll try to work on the fugit feature itself tomorrow, I've got an idea on how to make it tick.

thisismydesign commented 5 years ago

Thanks. Yep, that's the workaround in mind. I think the version dependencies are open-ended so theoretically, I could use this as soon as you can release. Do you foresee any other changes that would need to be done for the other gems? (not sure how involved you are with resque-scheduler)

jmettraux commented 5 years ago

I am not involved with Resque-Scheduler. Rufus-scheduler should be OK. I guess Resque-Scheduler delegates its cron parsing and validating to rufus-scheduler / fugit entirely. It should pass through once an updated fugit is available.

jmettraux commented 5 years ago

Hello,

I made good progress on that today, but on its et-orbi side. I'm fighting timezone tests on Windows.

I will continue tomorrow. Hopefully I can implement the proper fugit part of the solution.

jmettraux commented 5 years ago

Good morning @thisismydesign, if you could have a look at the implementation, that'd be much appreciated.

thisismydesign commented 5 years ago

Thank you @jmettraux, looking at the syntax it makes sense and would be great for us.

jmettraux commented 5 years ago

OK, I will then release tonight or tomorrow.

Thanks a lot.

thisismydesign commented 5 years ago

Thank you!

jmettraux commented 5 years ago

It's in today's fugit 1.1.10 release.