laravel调度程序在循环内

问题描述

当我在下面的代码中处理laravel排队的工作时,我感到困惑,它处理了user_id 1,2,3,4,5,但是当它在1分钟标记后运行时,它将尝试运行user_id 1,4 ,5再次,然后不再继续6,7,8,9,10。我想连续运行直到所有用户完成(这意味着我不知道何时完成所有用户的时间)。我该怎么办?

应用程序/控制台/内核

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use App\User;
use Illuminate\Support\Facades\File;
use App\Exceptions\Handler;
use App\Jobs\UserJob;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {   
        $users = User::where('is_status',1)->get();
        foreach( $users as $user ){
          $schedule->job( new UserJob($user) )->everyMinute();
        }
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');
        require base_path('routes/console.php');
    }
}

这是我的cronjob,每分钟运行一次

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)