Laravel:同时运行cron作业任务

问题描述:

我有几个计划在不同时间运行的任务。下面是这些任务:Laravel:同时运行cron作业任务

namespace App\Console; 

use Illuminate\Console\Scheduling\Schedule; 
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; 

class Kernel extends ConsoleKernel 
{ 
    /** 
    * The Artisan commands provided by your application. 
    * 
    * @var array 
    */ 
    protected $commands = [ 
     Commands\PostGetter::class 
    ]; 

    /** 
    * Define the application's command schedule. 
    * 
    * @param \Illuminate\Console\Scheduling\Schedule $schedule 
    * @return void 
    */ 
    protected function schedule(Schedule $schedule) 
    { 
     $schedule->command('post_getter 0 5') 
      ->cron('*/15 * * * *'); 

     $schedule->command('post_getter 5 10') 
      ->cron('*/15 * * * *'); 

     $schedule->command('post_getter 10 20') 
      ->everyThirtyMinutes(); 

     $schedule->command('post_getter 20 30') 
      ->hourly(); 
    } 
} 

为了记录这些任务在运行时,我已经添加在PostGetter类下面的代码登录当任务开始运行:

Log::info('Post getter for {arg1} and {arg2} has started.'); 

其中arg1arg2是调度程序中的两个参数(例如,0 55 10)。

我注意到在我的日志文件中,这些脚本似乎并不在同一时间运行。例如,当第一个任务运行时(post_getter 0 5),第二个任务(post_getter 5 10)似乎只在第一个任务完成后运行,依此类推。

我该怎么做才能让Kernel类中列出的所有任务同时运行,而无需等待上一个任务完成?

Laravel中的Cronjobs /计划进程运行sequentially

关于并行处理Laravel 4.3中的计划任务,有一个article。目前在Laravel 5中没有并行处理。

我通过添加自定义cron作业而不是通过Laravel调度程序来解决此问题。