Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/Commands/QueueFailedCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Doppar\Queue\Commands;

use Phaseolies\Console\Schedule\Command;
use Doppar\Queue\QueueManager;
use Doppar\Queue\Models\FailedJob;

class QueueFailedCommand extends Command
{
/**
* The name of the console command.
*
* @var string
*/
protected $name = 'queue:failed';

/**
* The command description.
*
* @var string
*/
protected $description = 'List all failed jobs';

/**
* Execute the console command
* Example: php pool queue:failed
*
* @return int
*/
protected function handle(): int
{
$failedJobs = FailedJob::orderBy('failed_at', 'desc')->get();

if ($failedJobs->isEmpty()) {
$this->info("No failed jobs found.");
return Command::SUCCESS;
}

// Create table
$table = $this->createTable();
$table->setHeaders(['ID', 'Job', 'Queue', 'Failed At']);

foreach ($failedJobs as $job) {
$payload = $job->payload;
$data = unserialize($payload);

$jobClass = null;
if ($data && isset($data['job']) && is_object($data['job'])) {
$jobClass = get_class($data['job']);
}

$failedAt = date('Y-m-d H:i:s', $job->failed_at);
$table->addRow([
$job->id,
$jobClass,
$job->queue,
$failedAt
]);
}

// Render table
$table->render();

return Command::SUCCESS;
}
}
8 changes: 5 additions & 3 deletions src/QueueServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace Doppar\Queue;

use Doppar\Queue\Commands\MakeJobCommand;
use Doppar\Queue\Commands\QueueFlushCommand;
use Phaseolies\Providers\ServiceProvider;
use Doppar\Queue\QueueManager;
use Doppar\Queue\Commands\QueueRunCommand;
use Doppar\Queue\Commands\QueueRetryCommand;
use Doppar\Queue\Commands\QueueFlushCommand;
use Doppar\Queue\Commands\QueueFailedCommand;
use Doppar\Queue\Commands\MakeJobCommand;

class QueueServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -38,7 +39,8 @@ public function boot(): void
QueueRunCommand::class,
QueueRetryCommand::class,
MakeJobCommand::class,
QueueFlushCommand::class
QueueFlushCommand::class,
QueueFailedCommand::class
]);
}
}
Loading