peppeocchi / php-cron-scheduler

PHP cron job scheduler
MIT License
811 stars 144 forks source link

About resetRun() #64

Closed playinteractive closed 6 years ago

playinteractive commented 6 years ago

Hi there,

I'm reading a list of cronjobs from the database but I'm not sure how to use resetRun():

$listCron = $db->query(bla bla bla)

while {

$scheduler->php($file)->at($schedule);
$scheduler->resetRun()->run();
}

or maybe:

while {

$scheduler->php($file)->at($schedule);
}

$scheduler->run();

Many thanks,

peppeocchi commented 6 years ago

@playinteractive the second block of code is the correct, you might need to call resetRun only if you want the same job to run multiple times in the same schedule.

Example

$scheduler->php('job1.php');
$scheduler->php('job2.php');
$scheduler->run();

// Then you want job1 to run again in the same schedule

$scheduler->resetRun();
$scheduler->php('job1');
$scheduler->run();
joshp23 commented 5 years ago

@peppeocchi

For clarity, I have the following wrapped in a function which is called by scheduler.php

    $scheduler = new Scheduler();

        $jobs = $db->querry;

    foreach ( $jobs as $job ) {
        $job[1] = $function;
        $job[2] = $schedule;
        $scheduler->call($function)->at($schedule)->onlyOne();
    }

    $scheduler->run();

In this instance there is no need to use either clearJobs() or resetRun() when calling this every minute, yes?