2016-05-17 229 views
2

我有幾個計劃在不同時間運行的任務。下面是這些任務: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類中列出的所有任務同時運行,而無需等待上一個任務完成?

回答

0

Laravel中的Cronjobs /計劃進程運行sequentially

關於並行處理Laravel 4.3中的計劃任務,有一個article。目前在Laravel 5中沒有並行處理。

0

我通過添加自定義cron作業而不是通過Laravel調度程序來解決此問題。