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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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`

## [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
94 changes: 87 additions & 7 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,
],
],

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``
- Uses the default connection by default. The database connection used to store jobs. It must be a ``mongodb`` connection.

* - ``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``
- Default ``60``. Specify how many seconds the queue connection should wait before retrying a job that is being processed

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``
- Uses the default connection by default. The database connection used to store jobs. It must be a ``mongodb`` connection.

* - ``collection``
- Default ``failed_jobs``. Name of the MongoDB collection to store 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 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 this feature.
The collection ``job_batches`` will be 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``
- Uses the default connection by default. The database connection used to store jobs. It must be a ``mongodb`` connection.

* - ``collection``
- Default ``job_batches``. Name of the MongoDB collection to store 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