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.

    评论

报告相同问题?

悬赏问题

  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 武汉岩海低应变分析软件,导数据库里不显示波形图
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile