Last active
December 18, 2023 17:15
-
-
Save esilvajr/fad83cd1c354d88b97ced580e3e24037 to your computer and use it in GitHub Desktop.
Execute Laravel failed_queue from database using chunk and wait.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
use Illuminate\Database\Eloquent\Model; | |
use Illuminate\Support\Facades\Artisan; | |
class QueueFailedChunkCommand extends Command | |
{ | |
protected $signature = 'queue:failed-chunk {--size=} {--wait=}'; | |
protected $description = 'Execute the failed_queue from database using chunk and wait.'; | |
public function handle() | |
{ | |
(new class extends Model { | |
CONST ATTR = ["uuid"]; | |
protected $table = "failed_jobs"; | |
protected $fillable = self::ATTR; | |
protected $attributes = self::ATTR; | |
})::chunk($this->option('size')??100, function($failedJobs) { | |
foreach ($failedJobs as $job) { | |
Artisan::call("queue:retry " . $job->uuid); | |
print(Artisan::output()); | |
} | |
sleep($this->option('wait')??5); | |
}); | |
} | |
} |
Create the file in app/Console/Commands
directory.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use
php artisan queue:failed-chunk --size=100 --wait=60
on CLI.