dongwei1855 2016-05-17 17:39
浏览 232

Laravel:同时运行cron作业任务

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?

  • 写回答

2条回答 默认 最新

  • down_load1117 2016-05-17 17:50
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?