0

当我运行下面的代码时,我对 laravel 排队作业感到困惑,它处理 user_id 1,2,3,4,5 但是当它在 1 分钟标记后运行时,它将尝试再次运行 user_id 1,2,3,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
4

1 回答 1

0

你有没有试过给它起个名字,然后在它完成之前添加而不用研磨,也许是它的开始。我正在努力解决类似的问题。

->name('Process Whatever')
->withoutOverlapping()
于 2021-07-24T13:27:51.400 回答