Search code examples
phplaravellaravel-5cronscheduled-tasks

Schedule job in laravel time interval


I have three schedule job every hour in Kernel.php like below:

$schedule->command('get:twitter')->cron('* 1 * * * *');
$schedule->command('get:facebook')->cron('* 1 * * * *');
$schedule->command('get:googleplus')->cron('* 1 * * * *');

I want to run this three schedule in some time interval like below:

$schedule->command('get:twitter')->cron('* 1 * * * *');//after 1 hour
$schedule->command('get:facebook')->cron('30 1 * * * *');//after 1.30 hour
$schedule->command('get:googleplus')->cron('45 1 * * * *');//after 1.45 hour

Is this possible in laravel 5.1


Solution

  • There is no anything out of box but you can do something like this:

    // every hour
    $schedule->command('get:twitter')->hourly();
    
    // every one and a half hours
    $schedule->command('get:facebook')->cron('0 0,3,6,9,12,15,18,21 * * * *');
    $schedule->command('get:facebook')->cron('30 1,4,7,10,13,16,19,22 * * * *');
    
    // every two hours at x.15 minutes (0.15, 2.15, 4.15 etc)
    $schedule->command('get:googleplus')->cron('15 */2 * * * *');