Skip to content

Instantly share code, notes, and snippets.

@esilvajr
Last active December 18, 2023 17:15
Show Gist options
  • Save esilvajr/fad83cd1c354d88b97ced580e3e24037 to your computer and use it in GitHub Desktop.
Save esilvajr/fad83cd1c354d88b97ced580e3e24037 to your computer and use it in GitHub Desktop.
Execute Laravel failed_queue from database using chunk and wait.
<?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);
});
}
}
@esilvajr
Copy link
Author

Use php artisan queue:failed-chunk --size=100 --wait=60 on CLI.

@esilvajr
Copy link
Author

esilvajr commented Dec 18, 2023

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