0

I am confused in laravel queued jobs when I run the code below it processes user_id 1,2,3,4,5 but when it's running after the 1 minute mark it will try to run user_id 1,2,3,4,5 again and not continue with 6,7,8,9,10. I want to run this continuously until it finishes through all the users (meaning I don't know the timing when it will finish going through all the users). How do I go about this?

app/console/kernel

<?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');
    }
}

this is my cronjob which runs every minute

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

1 Answer 1

0

Have you tried giving it a name and add without lapping, perhaps its starting, before its finished. I was struggling with a similar problem.

->name('Process Whatever')
->withoutOverlapping()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.