You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/docs/utils/queues.md
+60-9Lines changed: 60 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -134,12 +134,30 @@ dispatch([
134
134
135
135
## Specifying options for a job
136
136
137
-
In the Worker config, you can specify default options for your jobs. However, you can also specify options for a job when dispatching it to the queue. For example, if you want to delay a job for 5 minutes, you can do so by passing the `delay` option to the `dispatch()` method:
137
+
There are times when you need a job to behave a specific way, for instance, you may want to delay a job for a few minutes or specify the number of times a job should be attempted. You can do that by directly setting the options on the job:
protected $tries = 1; // try job only once (default 3) // [!code ++]
151
+
152
+
/**
153
+
* Handle the job.
154
+
* @return void
155
+
*/
156
+
public function handle($userId)
157
+
{
158
+
UserMailer::welcome($userId)->send();
159
+
}
160
+
}
143
161
```
144
162
145
163
The available options are:
@@ -156,7 +174,7 @@ The available options are:
156
174
157
175
Without a worker running, your jobs will just sit in the queue without being processed.
158
176
159
-
## Batching Jobs
177
+
<!--## Batching Jobs
160
178
161
179
You can use batches to to queue multiple jobs in sequence—they will be processed in the order they were dispatched. The key advantage of batching is that it allows you to specify a callback that runs only after all the jobs have been completed. This is useful for cases where you need to perform an action after a set of jobs finishes successfully, such as logging the results or notifying a user when all tasks are done. To create a batch, you can use the `g:job` command:
162
180
@@ -198,7 +216,7 @@ You can then dispatch the batch to the queue:
198
216
199
217
```php:no-line-numbers
200
218
dispatch(ProcessPodcastBatch::class);
201
-
```
219
+
```-->
202
220
203
221
## Limitations of Queues/Workers
204
222
@@ -241,7 +259,7 @@ return [
241
259
| used by your application. An example configuration is provided for
242
260
| each backend supported by Leaf. You're also free to add more.
You can change the default queue connection, the queue connections, and the table name for the database queue. You can also add more queue connections if you want to use a different queue backend.
281
+
You can set up multiple queue connections, and Leaf will connect to them when a job is run. For now, only database queues are supported, but we are working on redis and file drivers which will be available pretty soon.
282
+
283
+
## Using a different connection
284
+
285
+
Once you have configured another database connection, you can run a job using that queue connection by specifying it inside the job you create like this:
286
+
287
+
```php
288
+
<?php
289
+
290
+
namespace App\Jobs;
291
+
292
+
use Leaf\Job;
293
+
use App\Mailers\UserMailer;
294
+
295
+
class SendEmailJob extends Job
296
+
{
297
+
protected $connection = 'myOtherConnection';
298
+
299
+
/**
300
+
* Handle the job.
301
+
* @return void
302
+
*/
303
+
public function handle($userId)
304
+
{
305
+
UserMailer::welcome($userId)->send();
306
+
}
307
+
}
308
+
```
309
+
310
+
From there, you can dispatch the job just as you always do:
0 commit comments