|
7 | 7 | use Illuminate\Container\Container;
|
8 | 8 | use Illuminate\Contracts\Encryption\Encrypter;
|
9 | 9 | use Illuminate\Contracts\Queue\ShouldBeEncrypted;
|
| 10 | +use Illuminate\Queue\Events\JobQueued; |
10 | 11 | use Illuminate\Support\Arr;
|
11 | 12 | use Illuminate\Support\InteractsWithTime;
|
12 | 13 | use Illuminate\Support\Str;
|
@@ -284,13 +285,17 @@ protected function enqueueUsing($job, $payload, $queue, $delay, $callback)
|
284 | 285 | if ($this->shouldDispatchAfterCommit($job) &&
|
285 | 286 | $this->container->bound('db.transactions')) {
|
286 | 287 | return $this->container->make('db.transactions')->addCallback(
|
287 |
| - function () use ($payload, $queue, $delay, $callback) { |
288 |
| - return $callback($payload, $queue, $delay); |
| 288 | + function () use ($payload, $queue, $delay, $callback, $job) { |
| 289 | + return tap($callback($payload, $queue, $delay), function ($jobId) use ($job) { |
| 290 | + $this->raiseJobQueuedEvent($jobId, $job); |
| 291 | + }); |
289 | 292 | }
|
290 | 293 | );
|
291 | 294 | }
|
292 | 295 |
|
293 |
| - return $callback($payload, $queue, $delay); |
| 296 | + return tap($callback($payload, $queue, $delay), function ($jobId) use ($job) { |
| 297 | + $this->raiseJobQueuedEvent($jobId, $job); |
| 298 | + }); |
294 | 299 | }
|
295 | 300 |
|
296 | 301 | /**
|
@@ -345,4 +350,18 @@ public function setContainer(Container $container)
|
345 | 350 | {
|
346 | 351 | $this->container = $container;
|
347 | 352 | }
|
| 353 | + |
| 354 | + /** |
| 355 | + * Raise the job queued event. |
| 356 | + * |
| 357 | + * @param string|int|null $jobId |
| 358 | + * @param \Closure|string|object $job |
| 359 | + * @return void |
| 360 | + */ |
| 361 | + protected function raiseJobQueuedEvent($jobId, $job) |
| 362 | + { |
| 363 | + if ($this->container->bound('events')) { |
| 364 | + $this->container['events']->dispatch(new JobQueued($jobId, $job)); |
| 365 | + } |
| 366 | + } |
348 | 367 | }
|
0 commit comments