GithubHelp home page GithubHelp logo

Comments (5)

mark-win avatar mark-win commented on May 20, 2024 2

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.

from php-cron-scheduler.

peppeocchi avatar peppeocchi commented on May 20, 2024 2

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

  1. if you're trying to avoid the same script to overlap, you can use the onlyOne method. That will make sure that if the script is currently being executed by the previous cron cycle (e.g. if the script takes more that 1 minute to execute), it won't run the next minute.
    $scheduler->php('script.php')->onlyOne()
  2. if you're trying to avoid the script to run in the same interval (also if not overlapping), you can write a simple solution by using the then (docs) method, keeping the last execution time (somewhere, in a db for example) and checking that on top of your script (or inside the scheduler.php file).
// 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.

from php-cron-scheduler.

drupalista-br avatar drupalista-br commented on May 20, 2024

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.

from php-cron-scheduler.

joshp23 avatar joshp23 commented on May 20, 2024

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?

from php-cron-scheduler.

peppeocchi avatar peppeocchi commented on May 20, 2024

@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

from php-cron-scheduler.

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.