Skip to content

Commit bd20e72

Browse files
committed
Update docs and review option names
1 parent 19d0fbe commit bd20e72

File tree

3 files changed

+114
-11
lines changed

3 files changed

+114
-11
lines changed

docs/queues.txt

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Queues
1111
.. meta::
1212
:keywords: php framework, odm, code example
1313

14-
If you want to use MongoDB as your database backend for Laravel Queue, change
14+
If you want to use MongoDB as your database backend for Laravel Queue, change
1515
the driver in ``config/queue.php``:
1616

1717
.. code-block:: php
@@ -20,27 +20,108 @@ the driver in ``config/queue.php``:
2020
'database' => [
2121
'driver' => 'mongodb',
2222
// You can also specify your jobs specific database created on config/database.php
23-
'connection' => 'mongodb-job',
24-
'table' => 'jobs',
23+
'connection' => 'mongodb',
24+
'collection' => 'jobs',
2525
'queue' => 'default',
2626
'expire' => 60,
2727
],
2828
],
2929

30-
If you want to use MongoDB to handle failed jobs, change the database in
30+
.. list-table::
31+
:header-rows: 1
32+
:widths: 25 75
33+
34+
* - Setting
35+
- Description
36+
37+
* - ``driver``
38+
- **Required**. Specifies the queue driver to use. Must be ``mongodb``.
39+
40+
* - ``connection``
41+
- Uses the default connection by default. The database connection used to store jobs. It must be a ``mongodb`` connection.
42+
43+
* - ``collection``
44+
- **Required**. Name of the MongoDB collection to store jobs to process.
45+
46+
* - ``queue``
47+
- **Required**. Name of the queue.
48+
49+
* - ``retry_after``
50+
- Default ``60``. Specify how many seconds the queue connection should wait before retrying a job that is being processed
51+
52+
If you want to use MongoDB to handle failed jobs, change the database in
3153
``config/queue.php``:
3254

3355
.. code-block:: php
3456

3557
'failed' => [
3658
'driver' => 'mongodb',
37-
// You can also specify your jobs specific database created on config/database.php
38-
'database' => 'mongodb-job',
39-
'table' => 'failed_jobs',
59+
'database' => 'mongodb',
60+
'collection' => 'failed_jobs',
4061
],
4162

63+
.. list-table::
64+
:header-rows: 1
65+
:widths: 25 75
66+
67+
* - Setting
68+
- Description
69+
70+
* - ``driver``
71+
- **Required**. Specifies the queue driver to use. Must be ``mongodb``.
72+
73+
* - ``connection``
74+
- Uses the default connection by default. The database connection used to store jobs. It must be a ``mongodb`` connection.
75+
76+
* - ``collection``
77+
- Default ``failed_jobs``. Name of the MongoDB collection to store failed jobs.
78+
79+
4280
Add the service provider in ``config/app.php``:
4381

4482
.. code-block:: php
4583

4684
MongoDB\Laravel\MongoDBQueueServiceProvider::class,
85+
86+
87+
Job Batching
88+
------------
89+
90+
`Laravel's job batching https://laravel.com/docs/{+laravel-docs-version+}/queues#job-batching>`__
91+
feature allows you to easily execute a batch of jobs and then perform some action
92+
when the batch of jobs has completed executing.
93+
94+
With MongoDB, you don't have to create any collection before using this feature.
95+
The collection ``job_batches`` will be created automatically to store meta
96+
information about your job batches, such as their completion percentage
97+
98+
99+
.. code-block:: php
100+
101+
'batching' => [
102+
'driver' => 'mongodb',
103+
'database' => 'mongodb',
104+
'collection' => 'job_batches',
105+
],
106+
107+
.. list-table::
108+
:header-rows: 1
109+
:widths: 25 75
110+
111+
* - Setting
112+
- Description
113+
114+
* - ``driver``
115+
- **Required**. Specifies the queue driver to use. Must be ``mongodb``.
116+
117+
* - ``connection``
118+
- Uses the default connection by default. The database connection used to store jobs. It must be a ``mongodb`` connection.
119+
120+
* - ``collection``
121+
- Default ``job_batches``. Name of the MongoDB collection to store job batches.
122+
123+
Add the service provider in ``config/app.php``:
124+
125+
.. code-block:: php
126+
127+
MongoDB\Laravel\MongoDBBusServiceProvider::class,

src/MongoDBQueueServiceProvider.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use MongoDB\Laravel\Queue\Failed\MongoFailedJobProvider;
1010

1111
use function array_key_exists;
12+
use function trigger_error;
13+
14+
use const E_USER_DEPRECATED;
1215

1316
class MongoDBQueueServiceProvider extends QueueServiceProvider
1417
{
@@ -51,6 +54,11 @@ protected function registerFailedJobServices()
5154
*/
5255
protected function mongoFailedJobProvider(array $config): MongoFailedJobProvider
5356
{
54-
return new MongoFailedJobProvider($this->app['db'], $config['database'], $config['table']);
57+
if (! isset($config['collection']) && isset($config['table'])) {
58+
trigger_error('Since mongodb/laravel-mongodb 4.4: Using "table" option for the queue is deprecated. Use "collection" instead.', E_USER_DEPRECATED);
59+
$config['collection'] = $config['table'];
60+
}
61+
62+
return new MongoFailedJobProvider($this->app['db'], $config['database'], $config['collection'] ?? 'failed_jobs');
5563
}
5664
}

src/Queue/MongoConnector.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
use Illuminate\Database\ConnectionResolverInterface;
99
use Illuminate\Queue\Connectors\ConnectorInterface;
1010

11+
use function trigger_error;
12+
13+
use const E_USER_DEPRECATED;
14+
1115
class MongoConnector implements ConnectorInterface
1216
{
1317
/**
@@ -32,11 +36,21 @@ public function __construct(ConnectionResolverInterface $connections)
3236
*/
3337
public function connect(array $config)
3438
{
39+
if (! isset($config['collection']) && isset($config['table'])) {
40+
trigger_error('Since mongodb/laravel-mongodb 4.4: Using "table" option in queue configuration is deprecated. Use "collection" instead.', E_USER_DEPRECATED);
41+
$config['collection'] = $config['table'];
42+
}
43+
44+
if (! isset($config['retry_after']) && isset($config['expire'])) {
45+
trigger_error('Since mongodb/laravel-mongodb 4.4: Using "expire" option in queue configuration is deprecated. Use "retry_after" instead.', E_USER_DEPRECATED);
46+
$config['retry_after'] = $config['expire'];
47+
}
48+
3549
return new MongoQueue(
3650
$this->connections->connection($config['connection'] ?? null),
37-
$config['table'],
38-
$config['queue'],
39-
$config['expire'] ?? 60,
51+
$config['collection'] ?? 'jobs',
52+
$config['queue'] ?? 'default',
53+
$config['retry_after'] ?? 60,
4054
);
4155
}
4256
}

0 commit comments

Comments
 (0)