Skip to content

Commit 612b46c

Browse files
XbNzsimonhamp
andauthored
Child process queue docs (#69)
* document child process queues fix accidental package-lock update * Copy --------- Co-authored-by: Simon Hamp <[email protected]>
1 parent 08bd57a commit 612b46c

File tree

1 file changed

+56
-4
lines changed
  • resources/views/docs/1/digging-deeper

1 file changed

+56
-4
lines changed

resources/views/docs/1/digging-deeper/queues.md

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,64 @@ Jobs live in the SQLite [database](/docs/digging-deeper/databases) that your app
1515
migration will have been created and migrated for you.
1616

1717
## Processing Jobs / Working the Queue
18-
When your application boots up, NativePHP starts a single queue worker, ready to process any jobs you send its way.
18+
By default, NativePHP will boot up a single queue worker which will consume jobs from the `default` queue.
1919

20-
There's nothing more required.
20+
If you wish to modify the configuration of this worker or run more workers, see [Configuring workers](#configuring-workers).
2121

22-
In the context of your user's device, it's very rare that you would need multiple queues or many workers, as your
23-
application is likely to only be used by one user at a time.
22+
### Configuring workers
23+
Once you publish the NativePHP config file using `php artisan vendor:publish`, you will find a `queue_workers` key in
24+
`config/nativephp.php`. Here are some acceptable values to get you started:
25+
26+
```php
27+
'queue_workers' => [
28+
'one' => [],
29+
'two' => [],
30+
'three' => [
31+
'queues' => ['high'],
32+
'memory_limit' => 1024,
33+
'timeout' => 600,
34+
],
35+
'four' => [
36+
'queues' => ['high'],
37+
],
38+
'five' => [
39+
'memory_limit' => 1024,
40+
],
41+
],
42+
```
43+
44+
Each item in the array will be spun up as a persistent [Child Process](/docs/digging-deeper/child-processes), with the key
45+
name you provide being used as both the process's and the worker's alias.
46+
47+
You may configure which queues a worker is able to process jobs from, its memory limit and its timeout.
48+
49+
If you do not provide values for any of these settings, the following sensible defaults will be used:
50+
51+
```php
52+
'queues' => ['default'],
53+
'memory_limit' => 128,
54+
'timeout' => 60,
55+
```
56+
57+
### Managing workers
58+
59+
The handy `QueueWorker::up()` and `QueueWorker::down()` methods available on `Facades\QueueWorker` can be used to start
60+
and stop workers, should you need to.
61+
62+
```php
63+
use Native\DTOs\QueueConfig;
64+
use Native\Laravel\Facades\QueueWorker;
65+
66+
$queueConfig = new QueueConfig(alias: 'manual', queuesToConsume: ['default'], memoryLimit: 1024, timeout: 600);
67+
68+
QueueWorker::up($queueConfig);
69+
70+
// Alternatively, if you already have the worker config in your config/nativephp.php file, you may simply use its alias:
71+
QueueWorker::up(alias: 'manual');
72+
73+
// Later...
74+
QueueWorker::down(alias: 'manual');
75+
```
2476

2577
## When to Queue
2678
Given that your database and application typically exist on the same machine (i.e. there's no network involved),

0 commit comments

Comments
 (0)