Comments (7)
Hi Troy,
Yes you can. Please test this:
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
}
});
from cron.
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.
from cron.
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.
from cron.
I added the $lastRun
parameter to the cron.afterRun
event. Please test.
from cron.
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.
from cron.
You are right, Troy. It is not a good solution to add the $lastRun
parameter to the event only if there was a Cron run before. I changed this with commit e894e8e, updated the test cases and corrected the readme file at the events section. Now you always get this event parameter but it could be an empty array. Please test again. Thank you for improving Cron.
from cron.
Closed due to inactivity.
from cron.
Related Issues (20)
- Are tests working? HOT 2
- Incompatibility with Laravel 8, 9 HOT 1
- Exception with two closures on the same line of code HOT 3
- Symfony\Component\Console\Helper\HelperSet->get('table') HOT 3
- usage question: loading jobs from database HOT 3
- command cron:run/list error HOT 1
- stop cronjob run during beforeRun event HOT 3
- Cron job running only one time HOT 3
- Pull request #80 not in composer package HOT 3
- trying to understand why I should use this over Laravel's built-in scheduler HOT 2
- Which user should run cron HOT 2
- Laravel 5.4 support HOT 3
- PHP Fatal error: Class 'App\Providers\Cron' not found in C:\xampp\htdocs\isend\blog\app\Providers\AppServiceProvider.php on line 33 HOT 3
- laravel5.2.45 install failed HOT 2
- passing variable to the function parameter before adding a cron HOT 5
- Have Undefined index while run the cron job!!! HOT 3
- Php artisan cron:run Not working HOT 13
- Can't use `artisan route:cache` because the built-in cron route uses a closure HOT 5
- [Laravel 5.6] Ambiguous class resolution warning HOT 10
- doesn't work with Laravel 5.8 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cron.