|
4 | 4 |
|
5 | 5 | use Carbon\CarbonImmutable; |
6 | 6 | use Illuminate\Config\Repository; |
| 7 | +use Illuminate\Events\CallQueuedListener; |
7 | 8 | use Illuminate\Queue\Events\JobFailed; |
8 | 9 | use Illuminate\Queue\Events\JobProcessed; |
9 | 10 | use Illuminate\Queue\Events\JobProcessing; |
10 | 11 | use Illuminate\Queue\Events\JobQueued; |
11 | 12 | use Illuminate\Queue\Events\JobReleasedAfterException; |
12 | 13 | use Laravel\Pulse\Pulse; |
| 14 | +use ReflectionClass; |
13 | 15 |
|
14 | 16 | /** |
15 | 17 | * @internal |
@@ -57,10 +59,7 @@ public function record(JobReleasedAfterException|JobFailed|JobProcessed|JobProce |
57 | 59 | JobQueued::class => $event->connectionName, |
58 | 60 | default => $event->job->getConnectionName(), // @phpstan-ignore method.nonObject |
59 | 61 | }, |
60 | | - match ($class) { |
61 | | - JobQueued::class => $event->job->queue ?? null, |
62 | | - default => $event->job->getQueue(), // @phpstan-ignore method.nonObject |
63 | | - }, |
| 62 | + $this->resolveQueue($event), |
64 | 63 | match ($class) { |
65 | 64 | JobQueued::class => $event->payload()['uuid'], // @phpstan-ignore method.notFound |
66 | 65 | default => $event->job->uuid(), // @phpstan-ignore method.nonObject |
@@ -131,4 +130,31 @@ protected function normalizeSqsQueue(string $connection, string $queue): string |
131 | 130 |
|
132 | 131 | return $queue; |
133 | 132 | } |
| 133 | + |
| 134 | + /** |
| 135 | + * Resolve the queue. |
| 136 | + */ |
| 137 | + protected function resolveQueue(JobReleasedAfterException|JobFailed|JobProcessed|JobProcessing|JobQueued $event): ?string |
| 138 | + { |
| 139 | + return match ($event::class) { |
| 140 | + JobQueued::class => match (is_object($event->job) ? $event->job::class : $event->job) { |
| 141 | + CallQueuedListener::class => $this->resolveQueuedListenerQueue($event), |
| 142 | + default => $event->job->queue ?? null, |
| 143 | + }, |
| 144 | + default => $event->job->getQueue(), // @phpstan-ignore method.nonObject |
| 145 | + }; |
| 146 | + } |
| 147 | + |
| 148 | + /** |
| 149 | + * Resolve the queued listener's queue. |
| 150 | + */ |
| 151 | + protected function resolveQueuedListenerQueue(JobQueued $event): ?string |
| 152 | + { |
| 153 | + return with( |
| 154 | + (new ReflectionClass($event->job->class))->newInstanceWithoutConstructor(), // @phpstan-ignore property.nonObject |
| 155 | + fn ($listener) => method_exists($listener, 'viaQueue') |
| 156 | + ? $listener->viaQueue($event->job->data[0] ?? null) |
| 157 | + : ($listener->queue ?? null) |
| 158 | + ); |
| 159 | + } |
134 | 160 | } |
0 commit comments