Skip to content

Commit

Permalink
Show actual handler class names in queue console output.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jun 1, 2016
1 parent ace7f04 commit 4d7eb59
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Queue/Console/WorkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ protected function runWorker($connection, $queue, $delay, $memory, $daemon = fal
protected function writeOutput(Job $job, $failed)
{
if ($failed) {
$this->output->writeln('<error>['.Carbon::now()->format('Y-m-d H:i:s').'] Failed:</error> '.$job->getName());
$this->output->writeln('<error>['.Carbon::now()->format('Y-m-d H:i:s').'] Failed:</error> '.$job->resolveName());
} else {
$this->output->writeln('<info>['.Carbon::now()->format('Y-m-d H:i:s').'] Processed:</info> '.$job->getName());
$this->output->writeln('<info>['.Carbon::now()->format('Y-m-d H:i:s').'] Processed:</info> '.$job->resolveName());
}
}

Expand Down
23 changes: 23 additions & 0 deletions src/Illuminate/Queue/Jobs/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Queue\Jobs;

use DateTime;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

abstract class Job
Expand Down Expand Up @@ -258,6 +259,28 @@ public function getName()
return json_decode($this->getRawBody(), true)['job'];
}

/**
* Get the resolved name of the queued job class.
*
* @return string
*/
public function resolveName()
{
$name = $this->getName();

$payload = json_decode($this->getRawBody(), true);

if ($name === 'Illuminate\Queue\CallQueuedHandler@call') {
return Arr::get($payload, 'data.commandName', $name);
}

if ($name === 'Illuminate\Events\CallQueuedHandler@call') {
return $payload['data']['class'].'@'.$payload['data']['method'];
}

return $name;
}

/**
* Get the name of the queue the job belongs to.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function createPayload($job, $data = '', $queue = null)
} elseif (is_object($job)) {
return json_encode([
'job' => 'Illuminate\Queue\CallQueuedHandler@call',
'data' => ['command' => serialize(clone $job)],
'data' => ['commandName' => get_class($job), 'command' => serialize(clone $job)],
]);
}

Expand Down

0 comments on commit 4d7eb59

Please sign in to comment.