From caa3aa9629e1dd379e4ec10b94f339408bc8f361 Mon Sep 17 00:00:00 2001 From: bakaneko Date: Wed, 17 Apr 2024 21:41:37 +0900 Subject: [PATCH 1/4] log command name in metric instead of displayName; resolveName() calls payload(), so the data gets json_decoded again, anyway. --- app/Providers/AppServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 2bf3d0f79d7..ee86fa994e6 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -64,7 +64,7 @@ public function boot() $GLOBALS['cfg']['datadog-helper']['prefix_web'].'.queue.run', 1, [ - 'job' => $event->job->resolveName(), + 'job' => $event->job->payload()['data']['commandName'], 'queue' => $event->job->getQueue(), ] ); From c7bdfb9af88173cf75e1dd2e5614f6b4de56aa50 Mon Sep 17 00:00:00 2001 From: bakaneko Date: Wed, 24 Apr 2024 17:19:50 +0900 Subject: [PATCH 2/4] test commandName in job payload is the value we expect --- tests/Jobs/JobNameTest.php | 28 ++++++++++++++++++++++++++++ tests/Jobs/TestJob.php | 27 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tests/Jobs/JobNameTest.php create mode 100644 tests/Jobs/TestJob.php diff --git a/tests/Jobs/JobNameTest.php b/tests/Jobs/JobNameTest.php new file mode 100644 index 00000000000..615b190ecd6 --- /dev/null +++ b/tests/Jobs/JobNameTest.php @@ -0,0 +1,28 @@ +. Licensed under the GNU Affero General Public License v3.0. +// See the LICENCE file in the repository root for full licence text. + +declare(strict_types=1); + +namespace Tests\Jobs; + +use Illuminate\Queue\Events\JobProcessed; +use Queue; +use Tests\TestCase; + +class JobDisplayNameTest extends TestCase +{ + public function testDisplayName() + { + $job = new TestJob('test'); + + Queue::after(function (JobProcessed $event) use ($job) { + $this->assertSame($job::class, $event->job->payload()['data']['commandName']); + }); + + dispatch($job); + + $this->assertSame('test', $job->displayName()); + } +} diff --git a/tests/Jobs/TestJob.php b/tests/Jobs/TestJob.php new file mode 100644 index 00000000000..c1d21bbd916 --- /dev/null +++ b/tests/Jobs/TestJob.php @@ -0,0 +1,27 @@ +. Licensed under the GNU Affero General Public License v3.0. +// See the LICENCE file in the repository root for full licence text. + +namespace Tests\Jobs; + +use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; + +class TestJob implements ShouldQueue +{ + use Queueable; + + public function __construct(private $name) + { + } + + public function displayName() + { + return $this->name; + } + + public function handle() + { + } +} From efd371ed879779c8ff5ddc2033b89a78c0495112 Mon Sep 17 00:00:00 2001 From: bakaneko Date: Wed, 24 Apr 2024 17:23:41 +0900 Subject: [PATCH 3/4] wrong displayName test --- tests/Jobs/JobNameTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Jobs/JobNameTest.php b/tests/Jobs/JobNameTest.php index 615b190ecd6..3912c311b9f 100644 --- a/tests/Jobs/JobNameTest.php +++ b/tests/Jobs/JobNameTest.php @@ -18,11 +18,11 @@ public function testDisplayName() $job = new TestJob('test'); Queue::after(function (JobProcessed $event) use ($job) { - $this->assertSame($job::class, $event->job->payload()['data']['commandName']); + $payload = $event->job->payload(); + $this->assertSame($job::class, $payload['data']['commandName']); + $this->assertSame($job->displayName(), $payload['displayName']); }); dispatch($job); - - $this->assertSame('test', $job->displayName()); } } From 7f5b51421f72973d05dccbec93b4f5171522938b Mon Sep 17 00:00:00 2001 From: bakaneko Date: Wed, 24 Apr 2024 17:47:42 +0900 Subject: [PATCH 4/4] update name --- tests/Jobs/JobNameTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Jobs/JobNameTest.php b/tests/Jobs/JobNameTest.php index 3912c311b9f..e091de1d5df 100644 --- a/tests/Jobs/JobNameTest.php +++ b/tests/Jobs/JobNameTest.php @@ -11,7 +11,7 @@ use Queue; use Tests\TestCase; -class JobDisplayNameTest extends TestCase +class JobNameTest extends TestCase { public function testDisplayName() {