Git Product home page Git Product logo

Comments (7)

liebig avatar liebig commented on July 24, 2024

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.

tcarpenter2014 avatar tcarpenter2014 commented on July 24, 2024

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.

tcarpenter2014 avatar tcarpenter2014 commented on July 24, 2024

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.

liebig avatar liebig commented on July 24, 2024

I added the $lastRun parameter to the cron.afterRun event. Please test.

from cron.

tcarpenter2014 avatar tcarpenter2014 commented on July 24, 2024

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.

liebig avatar liebig commented on July 24, 2024

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.

liebig avatar liebig commented on July 24, 2024

Closed due to inactivity.

from cron.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.