fcron
fcron copied to clipboard
Implement -waitFinish flag
Hello, recently I needed to start the timer after it had finished the job.
This fcrontab will execute every 66 minutes @ 1h6 echo 'hello'
however, if you apply lock, it will not be consistent @ 1h6 flock -c 'echo "hello"'
Reference to an issue here: https://linux.org/threads/combining-crontab-with-fcrontab-timer-and-schedule.36474/
One solution that would improve the functionality of fcron would be to add -waitFinish flag, in which it will wait for specific job to start counting the timer for next job execution
May be it is better to use run-one
instead of flock -c
?
May be it is better to use
run-one
instead offlock -c
?
Could you provide example? I have never used run-one
, whatever that is. I'm happy to test the functionality of it and report back results
I suppose it will be:
@ 1h6 /usr/bin/run-one 'echo "hello"'
don't forget to install it - apt install run-one
for Ubuntu/deb-based distros. Unfortunately I do not know how to install it on rpm-based distros.
It seems like there is an alternative version for Debian: https://github.com/Freaky/run-one. From reading information about the package, it does similar thing to flock. It just prevents one and the same command from running simultaneously.
However, In this scenario- we are not running one and the same command, but 2 different ones that access the same resource, however only one can do it at a time, hence flock has been used. There is no issues with commands trying to run one after another, this works perfectly fine. Hence I believe there is no need for run-one as flock does the job.
It just becomes an issue because:
Job 1 starting at 8am for 5 minutes (8 * * * 8 echo 'hello job 1') Job 2 starting at 8:01am (@ 1h1 echo 'hello job 2'), will initialise fcron timer defined in @ 1h1 at 8:01am, even if the lock is present, which will prevent the command from running until after 8:05am, this is when it would be perfect to start counting beginning of the timer, hence I came up with additional tag.
I know it might be a rare scenario and not worth pursuing, if you feel like there is no need for this- feel free to close the issue. Otherwise I will be happy to do any testing on my end.
Thanks M
Have you looked into the 'serial' option (see http://fcron.free.fr/doc/en/fcrontab.5.html#FCRONTAB.5.SERIAL )? It may help here?
On Wed, 8 Sep 2021, 11:39 mackerel225, @.***> wrote:
It seems like there is an alternative version for Debian: https://github.com/Freaky/run-one. From reading information about the package, it does similar thing to flock. It just prevents one and the same command from running simultaneously.
However, In this scenario- we are not running one and the same command, but 2 different ones that access the same resource, however only one can do it at a time, hence flock has been used. There is no issues with commands trying to run one after another, this works perfectly fine. Hence I believe there is no need for run-one as flock does the job.
It just becomes an issue because:
Job 1 starting at 8am for 5 minutes (8 * * * 8 echo 'hello job 1') Job 2 starting at 8:01am (@ 1h1 echo 'hello job 2'), will initialise fcron timer defined in @ 1h1 at 8:01am, even if the lock is present, which will prevent the command from running until after 8:05am, this is when it would be perfect to start counting beginning of the timer, hence I came up with additional tag.
I know it might be a rare scenario and not worth pursuing, if you feel like there is no need for this- feel free to close the issue. Otherwise I will be happy to do any testing on my end.
Thanks M
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/yo8192/fcron/issues/13#issuecomment-915123012, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPHBIWQJGJBYNGPALQPIA3UA44OXANCNFSM5DSUU32Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Thanks @yo8192
Yes, it seems like it didn't really have any effect apart from adding the same job twice with bool(true), here are the results with bool(false) and bool(true):
fcrontab script:
!serial(false) 07 * * * * /usr/bin/flock -x /tmp/test.lockfile -c '/home/pi/test/job1.sh >> /home/pi/test/log.txt' @ 2 /usr/bin/flock -x /tmp/test.lockfile -c '/home/pi/test/job2.sh >> /home/pi/test/log.txt'
log.txt output:
Running job 2... at Wed Sep 8 17:03:50 BST 2021 Running job 2... at Wed Sep 8 17:05:50 BST 2021 Running job 1 for 3 minutes... at Wed Sep 8 17:07:00 BST 2021 Running job 2... at Wed Sep 8 17:10:00 BST 2021 Running job 2... at Wed Sep 8 17:11:50 BST 2021 <<<<<<<<<<<<<<<<
expected output:
Running job 2... at Wed Sep 8 17:03:50 BST 2021 Running job 2... at Wed Sep 8 17:05:50 BST 2021 Running job 1 for 3 minutes... at Wed Sep 8 17:07:00 BST 2021 Running job 2... at Wed Sep 8 17:10:00 BST 2021 Running job 2... at Wed Sep 8 17:12:00 BST 2021 <<<<<<<<<<<<<<<<
fcrontab script:
!serial(true) 19 * * * * /usr/bin/flock -x /tmp/test.lockfile -c '/home/pi/test/job1.sh >> /home/pi/test/log.txt' @ 2 /usr/bin/flock -x /tmp/test.lockfile -c '/home/pi/test/job2.sh >> /home/pi/test/log.txt'
log.txt output:
Running job 2... at Wed Sep 8 17:15:50 BST 2021 Running job 2... at Wed Sep 8 17:17:50 BST 2021 Running job 1 for 3 minutes... at Wed Sep 8 17:19:00 BST 2021 Running job 2... at Wed Sep 8 17:22:00 BST 2021 Running job 2... at Wed Sep 8 17:22:00 BST 2021 Running job 2... at Wed Sep 8 17:23:50 BST 2021 <<<<<<<<<<<<<<<<
expected output:
Running job 2... at Wed Sep 8 17:15:50 BST 2021 Running job 2... at Wed Sep 8 17:17:50 BST 2021 Running job 1 for 3 minutes... at Wed Sep 8 17:19:00 BST 2021 Running job 2... at Wed Sep 8 17:22:00 BST 2021 Running job 2... at Wed Sep 8 17:22:00 BST 2021 Running job 2... at Wed Sep 8 17:24:00 BST 2021 <<<<<<<<<<<<<<<<