Skip to content

Commit 04dfa4e

Browse files
spoyntersmithSanderMuller
authored andcommitted
Fix typo (laravel#10001)
1 parent ecc940f commit 04dfa4e

File tree

1 file changed

+41
-146
lines changed

1 file changed

+41
-146
lines changed

queues.md

Lines changed: 41 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
- [Rate Limiting](#rate-limiting)
1313
- [Preventing Job Overlaps](#preventing-job-overlaps)
1414
- [Throttling Exceptions](#throttling-exceptions)
15-
- [Skipping Jobs](#skipping-jobs)
1615
- [Dispatching Jobs](#dispatching-jobs)
1716
- [Delayed Dispatching](#delayed-dispatching)
1817
- [Synchronous Dispatching](#synchronous-dispatching)
@@ -151,7 +150,6 @@ The following dependencies are needed for the listed queue drivers. These depend
151150
- Amazon SQS: `aws/aws-sdk-php ~3.0`
152151
- Beanstalkd: `pda/pheanstalk ~5.0`
153152
- Redis: `predis/predis ~2.0` or phpredis PHP extension
154-
- [MongoDB](https://www.mongodb.com/docs/drivers/php/laravel-mongodb/current/queues/): `mongodb/laravel-mongodb`
155153

156154
</div>
157155

@@ -183,12 +181,15 @@ Job classes are very simple, normally containing only a `handle` method that is
183181

184182
use App\Models\Podcast;
185183
use App\Services\AudioProcessor;
184+
use Illuminate\Bus\Queueable;
186185
use Illuminate\Contracts\Queue\ShouldQueue;
187-
use Illuminate\Foundation\Queue\Queueable;
186+
use Illuminate\Foundation\Bus\Dispatchable;
187+
use Illuminate\Queue\InteractsWithQueue;
188+
use Illuminate\Queue\SerializesModels;
188189

189190
class ProcessPodcast implements ShouldQueue
190191
{
191-
use Queueable;
192+
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
192193

193194
/**
194195
* Create a new job instance.
@@ -206,7 +207,7 @@ Job classes are very simple, normally containing only a `handle` method that is
206207
}
207208
}
208209

209-
In this example, note that we were able to pass an [Eloquent model](/docs/{{version}}/eloquent) directly into the queued job's constructor. Because of the `Queueable` trait that the job is using, Eloquent models and their loaded relationships will be gracefully serialized and unserialized when the job is processing.
210+
In this example, note that we were able to pass an [Eloquent model](/docs/{{version}}/eloquent) directly into the queued job's constructor. Because of the `SerializesModels` trait that the job is using, Eloquent models and their loaded relationships will be gracefully serialized and unserialized when the job is processing.
210211

211212
If your queued job accepts an Eloquent model in its constructor, only the identifier for the model will be serialized onto the queue. When the job is actually handled, the queue system will automatically re-retrieve the full model instance and its loaded relationships from the database. This approach to model serialization allows for much smaller job payloads to be sent to your queue driver.
212213

@@ -238,9 +239,8 @@ Or, to prevent relations from being serialized, you can call the `withoutRelatio
238239
/**
239240
* Create a new job instance.
240241
*/
241-
public function __construct(
242-
Podcast $podcast,
243-
) {
242+
public function __construct(Podcast $podcast)
243+
{
244244
$this->podcast = $podcast->withoutRelations();
245245
}
246246

@@ -253,8 +253,9 @@ If you are using PHP constructor property promotion and would like to indicate t
253253
*/
254254
public function __construct(
255255
#[WithoutRelations]
256-
public Podcast $podcast,
257-
) {}
256+
public Podcast $podcast
257+
) {
258+
}
258259

259260
If a job receives a collection or array of Eloquent models instead of a single model, the models within that collection will not have their relationships restored when the job is deserialized and executed. This is to prevent excessive resource usage on jobs that deal with large numbers of models.
260261

@@ -574,6 +575,7 @@ class ProviderIsDown
574575
{
575576
// ...
576577

578+
577579
public function middleware(): array
578580
{
579581
return [
@@ -586,6 +588,7 @@ class ProviderIsUp
586588
{
587589
// ...
588590

591+
589592
public function middleware(): array
590593
{
591594
return [
@@ -612,18 +615,18 @@ For example, let's imagine a queued job that interacts with a third-party API th
612615
*/
613616
public function middleware(): array
614617
{
615-
return [new ThrottlesExceptions(10, 5 * 60)];
618+
return [new ThrottlesExceptions(10, 5)];
616619
}
617620

618621
/**
619622
* Determine the time at which the job should timeout.
620623
*/
621624
public function retryUntil(): DateTime
622625
{
623-
return now()->addMinutes(30);
626+
return now()->addMinutes(5);
624627
}
625628

626-
The first constructor argument accepted by the middleware is the number of exceptions the job can throw before being throttled, while the second constructor argument is the number of seconds that should elapse before the job is attempted again once it has been throttled. In the code example above, if the job throws 10 consecutive exceptions, we will wait 5 minutes before attempting the job again, constrained by the 30-minute time limit.
629+
The first constructor argument accepted by the middleware is the number of exceptions the job can throw before being throttled, while the second constructor argument is the number of minutes that should elapse before the job is attempted again once it has been throttled. In the code example above, if the job throws 10 exceptions within 5 minutes, we will wait 5 minutes before attempting the job again.
627630

628631
When a job throws an exception but the exception threshold has not yet been reached, the job will typically be retried immediately. However, you may specify the number of minutes such a job should be delayed by calling the `backoff` method when attaching the middleware to the job:
629632

@@ -636,7 +639,7 @@ When a job throws an exception but the exception threshold has not yet been reac
636639
*/
637640
public function middleware(): array
638641
{
639-
return [(new ThrottlesExceptions(10, 5 * 60))->backoff(5)];
642+
return [(new ThrottlesExceptions(10, 5))->backoff(5)];
640643
}
641644

642645
Internally, this middleware uses Laravel's cache system to implement rate limiting, and the job's class name is utilized as the cache "key". You may override this key by calling the `by` method when attaching the middleware to your job. This may be useful if you have multiple jobs interacting with the same third-party service and you would like them to share a common throttling "bucket":
@@ -650,79 +653,12 @@ Internally, this middleware uses Laravel's cache system to implement rate limiti
650653
*/
651654
public function middleware(): array
652655
{
653-
return [(new ThrottlesExceptions(10, 10 * 60))->by('key')];
654-
}
655-
656-
By default, this middleware will throttle every exception. You can modify this behaviour by invoking the `when` method when attaching the middleware to your job. The exception will then only be throttled if closure provided to the `when` method returns `true`:
657-
658-
use Illuminate\Http\Client\HttpClientException;
659-
use Illuminate\Queue\Middleware\ThrottlesExceptions;
660-
661-
/**
662-
* Get the middleware the job should pass through.
663-
*
664-
* @return array<int, object>
665-
*/
666-
public function middleware(): array
667-
{
668-
return [(new ThrottlesExceptions(10, 10 * 60))->when(
669-
fn (Throwable $throwable) => $throwable instanceof HttpClientException
670-
)];
671-
}
672-
673-
If you would like to have the throttled exceptions reported to your application's exception handler, you can do so by invoking the `report` method when attaching the middleware to your job. Optionally, you may provide a closure to the `report` method and the exception will only be reported if the given closure returns `true`:
674-
675-
use Illuminate\Http\Client\HttpClientException;
676-
use Illuminate\Queue\Middleware\ThrottlesExceptions;
677-
678-
/**
679-
* Get the middleware the job should pass through.
680-
*
681-
* @return array<int, object>
682-
*/
683-
public function middleware(): array
684-
{
685-
return [(new ThrottlesExceptions(10, 10 * 60))->report(
686-
fn (Throwable $throwable) => $throwable instanceof HttpClientException
687-
)];
656+
return [(new ThrottlesExceptions(10, 10))->by('key')];
688657
}
689658

690659
> [!NOTE]
691660
> If you are using Redis, you may use the `Illuminate\Queue\Middleware\ThrottlesExceptionsWithRedis` middleware, which is fine-tuned for Redis and more efficient than the basic exception throttling middleware.
692661
693-
<a name="skipping-jobs"></a>
694-
### Skipping Jobs
695-
696-
The `Skip` middleware allows you to specify that a job should be skipped / deleted without needing to modify the job's logic. The `Skip::when` method will delete the job if the given condition evaluates to `true`, while the `Skip::unless` method will delete the job if the condition evaluates to `false`:
697-
698-
use Illuminate\Queue\Middleware\Skip;
699-
700-
/**
701-
* Get the middleware the job should pass through.
702-
*/
703-
public function middleware(): array
704-
{
705-
return [
706-
Skip::when($someCondition),
707-
];
708-
}
709-
710-
You can also pass a `Closure` to the `when` and `unless` methods for more complex conditional evaluation:
711-
712-
use Illuminate\Queue\Middleware\Skip;
713-
714-
/**
715-
* Get the middleware the job should pass through.
716-
*/
717-
public function middleware(): array
718-
{
719-
return [
720-
Skip::when(function (): bool {
721-
return $this->shouldSkip();
722-
}),
723-
];
724-
}
725-
726662
<a name="dispatching-jobs"></a>
727663
## Dispatching Jobs
728664

@@ -796,10 +732,6 @@ If you would like to specify that a job should not be immediately available for
796732
}
797733
}
798734

799-
In some cases, jobs may have a default delay configured. If you need to bypass this delay and dispatch a job for immediate processing, you may use the `withoutDelay` method:
800-
801-
ProcessPodcast::dispatch($podcast)->withoutDelay();
802-
803735
> [!WARNING]
804736
> The Amazon SQS queue service has a maximum delay time of 15 minutes.
805737
@@ -926,27 +858,6 @@ If you would like to specify the connection and queue that should be used for th
926858
new ReleasePodcast,
927859
])->onConnection('redis')->onQueue('podcasts')->dispatch();
928860

929-
<a name="adding-jobs-to-the-chain"></a>
930-
#### Adding Jobs to the Chain
931-
932-
Occasionally, you may need to prepend or append a job to an existing job chain from within another job in that chain. You may accomplish this using the `prependToChain` and `appendToChain` methods:
933-
934-
```php
935-
/**
936-
* Execute the job.
937-
*/
938-
public function handle(): void
939-
{
940-
// ...
941-
942-
// Prepend to the current chain, run job immediately after current job...
943-
$this->prependToChain(new TranscribePodcast);
944-
945-
// Append to the current chain, run job at end of chain...
946-
$this->appendToChain(new TranscribePodcast);
947-
}
948-
```
949-
950861
<a name="chain-failures"></a>
951862
#### Chain Failures
952863

@@ -967,7 +878,7 @@ When chaining jobs, you may use the `catch` method to specify a closure that sho
967878
> Since chain callbacks are serialized and executed at a later time by the Laravel queue, you should not use the `$this` variable within chain callbacks.
968879
969880
<a name="customizing-the-queue-and-connection"></a>
970-
### Customizing the Queue and Connection
881+
### Customizing The Queue and Connection
971882

972883
<a name="dispatching-to-a-particular-queue"></a>
973884
#### Dispatching to a Particular Queue
@@ -1007,12 +918,15 @@ Alternatively, you may specify the job's queue by calling the `onQueue` method w
1007918

1008919
namespace App\Jobs;
1009920

921+
use Illuminate\Bus\Queueable;
1010922
use Illuminate\Contracts\Queue\ShouldQueue;
1011-
use Illuminate\Foundation\Queue\Queueable;
923+
use Illuminate\Foundation\Bus\Dispatchable;
924+
use Illuminate\Queue\InteractsWithQueue;
925+
use Illuminate\Queue\SerializesModels;
1012926

1013927
class ProcessPodcast implements ShouldQueue
1014928
{
1015-
use Queueable;
929+
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
1016930

1017931
/**
1018932
* Create a new job instance.
@@ -1067,12 +981,15 @@ Alternatively, you may specify the job's connection by calling the `onConnection
1067981

1068982
namespace App\Jobs;
1069983

984+
use Illuminate\Bus\Queueable;
1070985
use Illuminate\Contracts\Queue\ShouldQueue;
1071-
use Illuminate\Foundation\Queue\Queueable;
986+
use Illuminate\Foundation\Bus\Dispatchable;
987+
use Illuminate\Queue\InteractsWithQueue;
988+
use Illuminate\Queue\SerializesModels;
1072989

1073990
class ProcessPodcast implements ShouldQueue
1074991
{
1075-
use Queueable;
992+
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
1076993

1077994
/**
1078995
* Create a new job instance.
@@ -1305,12 +1222,15 @@ To define a batchable job, you should [create a queueable job](#creating-jobs) a
13051222
namespace App\Jobs;
13061223

13071224
use Illuminate\Bus\Batchable;
1225+
use Illuminate\Bus\Queueable;
13081226
use Illuminate\Contracts\Queue\ShouldQueue;
1309-
use Illuminate\Foundation\Queue\Queueable;
1227+
use Illuminate\Foundation\Bus\Dispatchable;
1228+
use Illuminate\Queue\InteractsWithQueue;
1229+
use Illuminate\Queue\SerializesModels;
13101230

13111231
class ImportCsv implements ShouldQueue
13121232
{
1313-
use Batchable, Queueable;
1233+
use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
13141234

13151235
/**
13161236
* Execute the job.
@@ -1620,7 +1540,7 @@ Then, set the `queue.batching.driver` configuration option's value to `dynamodb`
16201540

16211541
```php
16221542
'batching' => [
1623-
'driver' => env('QUEUE_BATCHING_DRIVER', 'dynamodb'),
1543+
'driver' => env('QUEUE_FAILED_DRIVER', 'dynamodb'),
16241544
'key' => env('AWS_ACCESS_KEY_ID'),
16251545
'secret' => env('AWS_SECRET_ACCESS_KEY'),
16261546
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
@@ -1650,7 +1570,7 @@ If you defined your DynamoDB table with a `ttl` attribute, you may define config
16501570
<a name="queueing-closures"></a>
16511571
## Queueing Closures
16521572

1653-
Instead of dispatching a job class to the queue, you may also dispatch a closure. This is great for quick, simple tasks that need to be executed outside of the current request cycle. When dispatching closures to the queue, the closure's code content is cryptographically signed so that it cannot be modified in transit:
1573+
Instead of dispatching a job class to the queue, you may also dispatch a closure. This is great for quick, simple tasks that need to be executed outside of the current request cycle. When dispatching closures to the queue, the closure's code content is cryptographically signed so that it can not be modified in transit:
16541574

16551575
$podcast = App\Podcast::find(1);
16561576

@@ -1957,13 +1877,15 @@ When a particular job fails, you may want to send an alert to your users or reve
19571877

19581878
use App\Models\Podcast;
19591879
use App\Services\AudioProcessor;
1880+
use Illuminate\Bus\Queueable;
19601881
use Illuminate\Contracts\Queue\ShouldQueue;
1961-
use Illuminate\Foundation\Queue\Queueable;
1882+
use Illuminate\Queue\InteractsWithQueue;
1883+
use Illuminate\Queue\SerializesModels;
19621884
use Throwable;
19631885

19641886
class ProcessPodcast implements ShouldQueue
19651887
{
1966-
use Queueable;
1888+
use InteractsWithQueue, Queueable, SerializesModels;
19671889

19681890
/**
19691891
* Create a new job instance.
@@ -2351,29 +2273,6 @@ You may use the `assertDispatchedWithoutChain` method to assert that a job was p
23512273

23522274
Bus::assertDispatchedWithoutChain(ShipOrder::class);
23532275

2354-
<a name="testing-chain-modifications"></a>
2355-
#### Testing Chain Modifications
2356-
2357-
If a chained job [prepends or appends jobs to an existing chain](#adding-jobs-to-the-chain), you may use the job's `assertHasChain` method to assert that the job has the expected chain of remaining jobs:
2358-
2359-
```php
2360-
$job = new ProcessPodcast;
2361-
2362-
$job->handle();
2363-
2364-
$job->assertHasChain([
2365-
new TranscribePodcast,
2366-
new OptimizePodcast,
2367-
new ReleasePodcast,
2368-
]);
2369-
```
2370-
2371-
The `assertDoesntHaveChain` method may be used to assert that the job's remaining chain is empty:
2372-
2373-
```php
2374-
$job->assertDoesntHaveChain();
2375-
```
2376-
23772276
<a name="testing-chained-batches"></a>
23782277
#### Testing Chained Batches
23792278

@@ -2434,10 +2333,9 @@ In addition, you may occasionally need to test an individual job's interaction w
24342333

24352334
Sometimes, you may need to test that a queued job [releases itself back onto the queue](#manually-releasing-a-job). Or, you may need to test that the job deleted itself. You may test these queue interactions by instantiating the job and invoking the `withFakeQueueInteractions` method.
24362335

2437-
Once the job's queue interactions have been faked, you may invoke the `handle` method on the job. After invoking the job, the `assertReleased`, `assertDeleted`, `assertNotDeleted`, `assertFailed`, `assertFailedWith`, and `assertNotFailed` methods may be used to make assertions against the job's queue interactions:
2336+
Once the job's queue interactions have been faked, you may invoke the `handle` method on the job. After invoking the job, the `assetReleased`, `assertDeleted`, and `assertFailed` methods may be used to make assertions against the job's queue interactions:
24382337

24392338
```php
2440-
use App\Exceptions\CorruptedAudioException;
24412339
use App\Jobs\ProcessPodcast;
24422340

24432341
$job = (new ProcessPodcast)->withFakeQueueInteractions();
@@ -2446,10 +2344,7 @@ $job->handle();
24462344

24472345
$job->assertReleased(delay: 30);
24482346
$job->assertDeleted();
2449-
$job->assertNotDeleted();
24502347
$job->assertFailed();
2451-
$job->assertFailedWith(CorruptedAudioException::class);
2452-
$job->assertNotFailed();
24532348
```
24542349

24552350
<a name="job-events"></a>

0 commit comments

Comments
 (0)