I have several tasks that I've scheduled to run at various times. Here are those tasks:
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();
}
}
In order to log when each of these tasks is run, I've added the following piece of code in the PostGetter
class to log when the task has begun running:
Log::info('Post getter for {arg1} and {arg2} has started.');
Where arg1
and arg2
are the two arguments in the scheduler (e.g. 0 5
or 5 10
).
I've noticed in my log file that these scripts don't seem to run at the same time. For example, when the first task is run (post_getter 0 5
), the second task (post_getter 5 10
) only seems to run after the first task is done, and so on.
How can I make it so that all of the tasks listed in the Kernel
class are run at the same time and don't have to wait for the previous task to finish?
Cronjobs / scheduled processes in Laravel are run sequentially.
There is an article about parallel processing of scheduled tasks in Laravel 4.3. Currently there is no parallel processing in Laravel 5.
I solved this by adding custom cron jobs instead of running it through the Laravel scheduler.