Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduling on tuesday every other week #259

Closed
manveru opened this issue Sep 26, 2017 · 5 comments
Closed

Scheduling on tuesday every other week #259

manveru opened this issue Sep 26, 2017 · 5 comments
Assignees

Comments

@manveru
Copy link

manveru commented Sep 26, 2017

I'm trying to figure out a way to specify a schedule that occurs every two weeks on Tuesday. So far I've only come up with 0 0 * * tue#2,tue#4, which is not correct as a month may have between 4-5 Tuesdays.

Is there some way to solve this issue using Rufus::Scheduler::CronLine or should I implement a final check in my code and simply call it every Tuesday like Date.today.cweek % 2 == 0?

@jmettraux jmettraux self-assigned this Sep 26, 2017
@jmettraux
Copy link
Owner

Hello,

I did my own google search and every one seems to be implementing her/his own version of the "final check".

https://serverfault.com/questions/633264/cronjob-run-every-two-weeks-on-saturday-starting-on-this-saturday
https://stackoverflow.com/questions/350047/how-to-instruct-cron-to-execute-a-job-every-second-week

I'd say go with your final check.

Maybe I should allow for some kind of guard when setting up Rufus::Scheduler::CronLine (though future versions will use https://github.com/floraison/fugit)

Best regards and thanks for Ramaze and friends.

@manveru
Copy link
Author

manveru commented Sep 26, 2017

Thanks for the answer, I went ahead with the final check, it's a one-liner anyway but splits the logic in two places which I'm not a big fan of. Either way I think it'd be a pretty useful feature but it's understandable that you wouldn't implement something that's not supported by anything else (and would make calculations even more difficult).

@jmettraux
Copy link
Owner

Should it look like 0 0 * * tue/2? But then, odd versus even Tuesdays.

@jmettraux
Copy link
Owner

Moved issue to fugit where the parsing for future versions of rufus-scheduler is implemented.

Thanks again.

@jmettraux
Copy link
Owner

Another way:

scheduler.every('2w', first: next_tuesday_at_midnight()) do
  # ...
end

jmettraux added a commit to floraison/fugit that referenced this issue Apr 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants