Skip to content

PHPORM-81 implement mongodb driver for batch #2904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
May 21, 2024
Merged
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
## [4.4.0] - unreleased

* Support collection name prefix by @GromNaN in [#2930](https://github.com/mongodb/laravel-mongodb/pull/2930)
* Add `mongodb` driver for Batching by @GromNaN in [#2904](https://github.com/mongodb/laravel-mongodb/pull/2904)
* Rename queue option `table` to `collection`
* Replace queue option `expire` with `retry_after`

## [4.3.0] - 2024-04-26

Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
"spatie/laravel-query-builder": "^5.6",
"phpstan/phpstan": "^1.10"
},
"conflict": {
"illuminate/bus": "< 10.37.2"
},
"suggest": {
"mongodb/builder": "Provides a fluent aggregation builder for MongoDB pipelines"
},
Expand All @@ -62,7 +65,8 @@
"laravel": {
"providers": [
"MongoDB\\Laravel\\MongoDBServiceProvider",
"MongoDB\\Laravel\\MongoDBQueueServiceProvider"
"MongoDB\\Laravel\\MongoDBQueueServiceProvider",
"MongoDB\\Laravel\\MongoDBBusServiceProvider"
]
}
},
Expand Down
96 changes: 88 additions & 8 deletions docs/queues.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Queues
.. meta::
:keywords: php framework, odm, code example

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

.. code-block:: php
Expand All @@ -20,27 +20,107 @@ the driver in ``config/queue.php``:
'database' => [
'driver' => 'mongodb',
// You can also specify your jobs specific database created on config/database.php
'connection' => 'mongodb-job',
'table' => 'jobs',
'connection' => 'mongodb',
'collection' => 'jobs',
'queue' => 'default',
'expire' => 60,
'retry_after' => 60,
],
],

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: add an introductory sentence before the table, such as:
"The following table describes settings that you can specify to configure the behavior of the queue:"

If you want to use MongoDB to handle failed jobs, change the database in
.. list-table::
:header-rows: 1
:widths: 25 75

* - Setting
- Description

* - ``driver``
- **Required**. Specifies the queue driver to use. Must be ``mongodb``.

* - ``connection``
- The database connection used to store jobs. It must be a ``mongodb`` connection. The driver uses the default connection if a connection is not specified.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- The database connection used to store jobs. It must be a ``mongodb`` connection. The driver uses the default connection if a connection is not specified.
- Specifies the database connection used to store jobs. It must be a ``mongodb`` connection. The driver uses the default connection if a connection is not specified.


* - ``collection``
- **Required**. Name of the MongoDB collection to store jobs to process.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- **Required**. Name of the MongoDB collection to store jobs to process.
- **Required**. Specifies the name of the MongoDB collection to store jobs to process.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applies to all entries


* - ``queue``
- **Required**. Name of the queue.

* - ``retry_after``
- Specifies how many seconds the queue connection should wait before retrying a job that is being processed. Defaults to ``60``.

If you want to use MongoDB to handle failed jobs, change the database in
``config/queue.php``:

.. code-block:: php

'failed' => [
'driver' => 'mongodb',
// You can also specify your jobs specific database created on config/database.php
'database' => 'mongodb-job',
'table' => 'failed_jobs',
'database' => 'mongodb',
'collection' => 'failed_jobs',
],

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: same as earlier, add an introductory sentence to introduce this table

.. list-table::
:header-rows: 1
:widths: 25 75

* - Setting
- Description

* - ``driver``
- **Required**. Specifies the queue driver to use. Must be ``mongodb``.

* - ``connection``
- The database connection used to store jobs. It must be a ``mongodb`` connection. The driver uses the default connection if a connection is not specified.

* - ``collection``
- Name of the MongoDB collection to store failed jobs. Defaults to ``failed_jobs``.


Add the service provider in ``config/app.php``:

.. code-block:: php

MongoDB\Laravel\MongoDBQueueServiceProvider::class,


Job Batching
------------

`Job batching <https://laravel.com/docs/{+laravel-docs-version+}/queues#job-batching>`__
is a Laravel feature to execute a batch of jobs and subsequent actions before,
after, and during the execution of the jobs from the queue.

With MongoDB, you don't have to create any collection before using job batching.
The ``job_batches`` collection is created automatically to store meta
information about your job batches, such as their completion percentage.

.. code-block:: php

'batching' => [
'driver' => 'mongodb',
'database' => 'mongodb',
'collection' => 'job_batches',
],

.. list-table::
:header-rows: 1
:widths: 25 75

* - Setting
- Description

* - ``driver``
- **Required**. Specifies the queue driver to use. Must be ``mongodb``.

* - ``connection``
- The database connection used to store jobs. It must be a ``mongodb`` connection. The driver uses the default connection if a connection is not specified.

* - ``collection``
- Name of the MongoDB collection to store job batches. Defaults to ``job_batches``.

Add the service provider in ``config/app.php``:

.. code-block:: php

MongoDB\Laravel\MongoDBBusServiceProvider::class,
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
parameters:
ignoreErrors:
-
message: "#^Access to an undefined property Illuminate\\\\Container\\\\Container\\:\\:\\$config\\.$#"
count: 3
path: src/MongoDBBusServiceProvider.php

-
message: "#^Method Illuminate\\\\Database\\\\Eloquent\\\\Model\\:\\:push\\(\\) invoked with 3 parameters, 0 required\\.$#"
count: 2
Expand Down
Loading
Loading