fcron icon indicating copy to clipboard operation
fcron copied to clipboard

Implement -waitFinish flag

Open mackerel225 opened this issue 3 years ago • 6 comments

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

mackerel225 avatar Sep 07 '21 15:09 mackerel225

May be it is better to use run-one instead of flock -c ?

knutov avatar Sep 07 '21 17:09 knutov

May be it is better to use run-one instead of flock -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

mackerel225 avatar Sep 07 '21 22:09 mackerel225

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.

knutov avatar Sep 07 '21 22:09 knutov

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

mackerel225 avatar Sep 08 '21 10:09 mackerel225

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.

yo8192 avatar Sep 08 '21 14:09 yo8192

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 <<<<<<<<<<<<<<<<

mackerel225 avatar Sep 08 '21 16:09 mackerel225