-
Notifications
You must be signed in to change notification settings - Fork 142
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
How does it know when was the last time a job ran? #19
Comments
To put it simple: right, it does not know, when it ran the last time. The solution is to not run it more often than once per minute. This project relies on cron to be the only trigger but for dev reasons. Good thing is, cron won't trigger the command more often than once per minute, unless you really push it to do so. If you really need to make sure, that your task is not run more often, then you will have to do so by your own means. Either inside of the task itself or by modifying the trigger script (schedule.php) for a more global approach. |
@drupalista-br it's like @mark-win said, there is no way (out of the box) to know when it ran the last time, but it's true that the minimum interval for a cron job is 1 minute (in a real world scenario it won't run more than once per minute). I can suggest you two solutions based on what you need to do:
// Get last execution - pseudocode
$lastExecution = DB::get('last_execution')
->from('scripts_table')->where('name = script.php');
// If the last execution is more than one minute ago, then add the job to the scheduler
if ($lastExecution > '1 minute') {
$scheduler->php('script.php')->then(function () {
// After the job is executed, update the last execution time for the script
DB::update('scripts_table')
->where('name = script.php')->set('last_execution = now()');
});
} Of course if you have any other question please feel free to reopen this issue. |
Thank you guys. I am just playing around and learning. At this point I have no project requirements other than trying to understand the logic behind it. |
This comes to mind, if I have a job running once daily, and it misses a day due to ... some failure or other, I would like to be able to trigger it to run at the next available interval. Is there a way to que up over-due runs? |
@joshp23 not currently, I think you'll have to build external support to keep track of the jobs that did run and if that happens you should change the schedule for the jobs that didn't run. This might be easier if you store all your jobs in a database and you have an extra routine that checks for those kind of issue |
Here is my schedule.php content:
I executed
$ php schedule.php
. As expected, the file /tmp/my_file.log was created and had Hello World! in it.Immediately after that I emptied out /tmp/my_file.log and ran
$ php schedule.php
again. Since one minute has not passed, the /tmp/my_file.log should NOT get filled with Hello World! but it did. Why did it?The text was updated successfully, but these errors were encountered: