From 4d7eb59f9813723bab00b4e42ce9885b54e65778 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 31 May 2016 21:27:23 -0500 Subject: [PATCH] Show actual handler class names in queue console output. --- src/Illuminate/Queue/Console/WorkCommand.php | 4 ++-- src/Illuminate/Queue/Jobs/Job.php | 23 ++++++++++++++++++++ src/Illuminate/Queue/Queue.php | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Queue/Console/WorkCommand.php b/src/Illuminate/Queue/Console/WorkCommand.php index f37790469e51..a4555b137282 100755 --- a/src/Illuminate/Queue/Console/WorkCommand.php +++ b/src/Illuminate/Queue/Console/WorkCommand.php @@ -136,9 +136,9 @@ protected function runWorker($connection, $queue, $delay, $memory, $daemon = fal protected function writeOutput(Job $job, $failed) { if ($failed) { - $this->output->writeln('['.Carbon::now()->format('Y-m-d H:i:s').'] Failed: '.$job->getName()); + $this->output->writeln('['.Carbon::now()->format('Y-m-d H:i:s').'] Failed: '.$job->resolveName()); } else { - $this->output->writeln('['.Carbon::now()->format('Y-m-d H:i:s').'] Processed: '.$job->getName()); + $this->output->writeln('['.Carbon::now()->format('Y-m-d H:i:s').'] Processed: '.$job->resolveName()); } } diff --git a/src/Illuminate/Queue/Jobs/Job.php b/src/Illuminate/Queue/Jobs/Job.php index 304bc9dd90e5..4237e123c06f 100755 --- a/src/Illuminate/Queue/Jobs/Job.php +++ b/src/Illuminate/Queue/Jobs/Job.php @@ -3,6 +3,7 @@ namespace Illuminate\Queue\Jobs; use DateTime; +use Illuminate\Support\Arr; use Illuminate\Support\Str; abstract class Job @@ -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. * diff --git a/src/Illuminate/Queue/Queue.php b/src/Illuminate/Queue/Queue.php index 145b259f982c..b1588911572d 100755 --- a/src/Illuminate/Queue/Queue.php +++ b/src/Illuminate/Queue/Queue.php @@ -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)], ]); }