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

Already on GitHub? Sign in to your account

Allow times in seconds by chaining together tasks prefixed with multiple sleep commands #313

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants

Here's a way to support commands that need to run very frequently. If the time is less than a minute, it multiplies the task and prefixes each group with different sleep durations.

For example,

every 10.seconds do
  command 'echo "running frequent command"'
end

produces:

* * * * * /bin/bash -l -c '(echo "running frequent command") & 
(sleep 10 && echo "running frequent command") & 
(sleep 20 && echo "running frequent command") & 
(sleep 30 && echo "running frequent command") & 
(sleep 40 && echo "running frequent command") & 
(sleep 50 && echo "running frequent command")'

(all on one line.)

Just an idea, but I found it to be pretty useful.

Owner

javan commented Feb 4, 2013

That's clever. Jobs that run > 30.seconds, 45 seconds for example, would end up running at 0, 45, and then 0 again (15 seconds later) so it's not quite accurate.

Whenever has the same issue with tasks > 30.minutes, but it feels like a bigger issue when you're expecting second by second accuracy.

Thoughts?

How about only allowing times that are a factor of 60? There's still a lot of flexibility in: 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30

Jell commented Mar 6, 2013

I like this feature very much! As for jobs that run for T>30.seconds, you could find the Least Common Multiplier between T and 60, and then spread the number of cronjobs on as many seconds. i.e for 45.seconds:

LCM(60,45) = 180 = 3.minutes

*/3 * * * * (sleep 0   && echo 'hello')
*/3 * * * * (sleep 45  && echo 'hello')
*/3 * * * * (sleep 90  && echo 'hello')
*/3 * * * * (sleep 135 && echo 'hello')
Owner

javan commented May 12, 2013

Closing this for now. I don't want to get into the business of modifying cron's behavior. Another too may be more appropriate for sub-minute scheduling.

@javan javan closed this May 12, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment