Skip to content

Commit 5d52d87

Browse files
committed
feat: update queue docs
1 parent a7dce4a commit 5d52d87

File tree

1 file changed

+60
-9
lines changed

1 file changed

+60
-9
lines changed

src/docs/utils/queues.md

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,30 @@ dispatch([
134134

135135
## Specifying options for a job
136136

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:
138138

139-
```php:no-line-numbers
140-
dispatch(SendEmailJob::with($userId), [
141-
'delay' => 5
142-
]);
139+
```php
140+
<?php
141+
142+
namespace App\Jobs;
143+
144+
use Leaf\Job;
145+
use App\Mailers\UserMailer;
146+
147+
class SendEmailJob extends Job
148+
{
149+
protected $delay = 10; // add 10 sec delay // [!code ++]
150+
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+
}
143161
```
144162

145163
The available options are:
@@ -156,7 +174,7 @@ The available options are:
156174

157175
Without a worker running, your jobs will just sit in the queue without being processed.
158176

159-
## Batching Jobs
177+
<!-- ## Batching Jobs
160178
161179
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:
162180
@@ -198,7 +216,7 @@ You can then dispatch the batch to the queue:
198216
199217
```php:no-line-numbers
200218
dispatch(ProcessPodcastBatch::class);
201-
```
219+
``` -->
202220

203221
## Limitations of Queues/Workers
204222

@@ -241,7 +259,7 @@ return [
241259
| used by your application. An example configuration is provided for
242260
| each backend supported by Leaf. You're also free to add more.
243261
|
244-
| Drivers: "redis", "database", "file (BETA)"
262+
| Drivers: "database", "redis (BETA)", "file (WIP)"
245263
|
246264
*/
247265
'connections' => [
@@ -260,7 +278,40 @@ return [
260278
];
261279
```
262280

263-
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:
311+
312+
```php:no-line-numbers
313+
dispatch(SendEmailJob::with($userId));
314+
```
264315

265316
## Deployment
266317

0 commit comments

Comments
 (0)