-
Notifications
You must be signed in to change notification settings - Fork 64
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
Checking for missed cron job? #37
Comments
Hi Troy, Event::listen('cron.afterRun', function($rundate, $inTime, $runtime, $errors, $crons, $lastrun){
if($inTime === -1) {
// No previous Cron runs found, do you run Cron the first time?
} elseif ($inTime) {
// Cron was called in time, so don't worry
} else {
// Whoops, Cron is not in time! You need to check this. In this block you can for example log this error or write a mail
}
}); |
Will the $crons array return a list of all the jobs that where supposed to run and didn't if $inTime is false or will it return a list of all the jobs I have added to cron? If $inTime is false I would really need cron.afterRun to return the job names that were supposed to run but didn't because the system was unavailable to run it at the time it was supposed to. |
In looking through the code I noticed that you do retrieve the last date the Cron was run in $lastRun variable. I think that could be a helpful parameter if it was passed to the cron.afterRun. That way when $inTime was false I could do a comparison to see how much time has elapsed since the last Cron run and determinations can be made from there how to proceed with that information. The issue is that I have a command that gets ran at a certain time of the day and sends out a text message when the Cron job executes. If this Cron job is not executed because the job was not ran I would need to make that determination in the cron.afterRun event I would want to call the command from that cron.afterRun event. If I have the previous run date and time to compare against the current run date and time I can then determine if the job that sends the text messages was supposed to be run within the time frame since the last Cron job was run. |
Fixing cron.afterRun event to pass the parameters to the listener as values and not as array Adding test case for the new cron.afterRun event and fixing the old one
I added the |
Since $lastrun does not get passed every time to the afterRun event you might want to update your documentation to look like this for the event: Event::listen('cron.afterRun', function($rundate, $inTime, $runtime, $errors, $crons, $lastrun = null){ }); If not setup this way then the Laravel log will fill up with missing argument exceptions really quick. Thanks for all your help. The enhancement works very well. |
You are right, Troy. It is not a good solution to add the |
Closed due to inactivity. |
Hi,
Is there a way using cron.afterRun and $inTime to check for a job not being run when it was supposed to? For example, I have the a job that gets added in a cron.collectJobs listener that is supposed to run everyday at a certain time and it just so happens that server reboot was required or maybe Laravel was down at that time. Would it be possible to detect that the cron job was not executed in the cron.afterRun so that I can execute the command that was supposed to be previously executed? If so, could you show a code example?
Thanks in advance,
Troy
The text was updated successfully, but these errors were encountered: