我有幾個計劃在不同時間運行的任務。下面是這些任務: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.');
其中arg1
和arg2
是調度程序中的兩個參數(例如,0 5
或5 10
)。
我注意到在我的日誌文件中,這些腳本似乎並不在同一時間運行。例如,當第一個任務運行時(post_getter 0 5
),第二個任務(post_getter 5 10
)似乎只在第一個任務完成後運行,依此類推。
我該怎麼做才能讓Kernel
類中列出的所有任務同時運行,而無需等待上一個任務完成?