@@ -15,12 +15,50 @@ Jobs live in the SQLite [database](/docs/digging-deeper/databases) that your app
15
15
migration will have been created and migrated for you.
16
16
17
17
## 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, there is no configuration needed to process jobs. The ` NativeServiceProvider::class ` will boot up one default worker
19
+ which will consume jobs from the ` default ` queue. If you want to run more workers or modify the configuration of any worker, you may
20
+ refer to [ Configuring workers] ( #configuring-workers ) .
19
21
20
- There's nothing more required.
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:
21
25
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.
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
+ Not providing a nested array for the ` memory_limit ` , ` queues ` and ` timeout ` will result in default values being used.
45
+
46
+ ### Managing workers
47
+
48
+ The handy ` QueueWorker::up() ` and ` QueueWorker::down() ` methods available on ` Facades\QueueWorker ` can be used to start
49
+ and stop workers in code. This is useful for niche scenarios, but is worth mentioning nonetheless.
50
+
51
+ ``` php
52
+ use Native\Laravel\Facades\QueueWorker;
53
+ use Native\DTOs\QueueConfig;
54
+
55
+ $queueConfig = new QueueConfig(alias: 'manual', queuesToConsume: ['default'], memoryLimit: 1024, timeout: 600);
56
+
57
+ QueueWorker::up($queueConfig);
58
+
59
+ // Later...
60
+ QueueWorker::down(alias: 'manual');
61
+ ```
24
62
25
63
## When to Queue
26
64
Given that your database and application typically exist on the same machine (i.e. there's no network involved),
0 commit comments