-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
mongodb
driver for batch
82ff224
to
7264181
Compare
$_SERVER['__progress.count']++; | ||
}) | ||
->then(function (Batch $batch) { | ||
$_SERVER['__then.batch'] = $batch; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't use $this
because the closure is serialized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would $this
be used here even if it was supported?
Offhand, is laravel/serializable-closure used internally for serialization? AFAIK, the stock serialize()
function doesn't support closures on its own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the $_SERVER['something']
could have been replaced by $this->data['something']
. But that's not allowed by the package you mentioned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about assuming that any string passed will be a valid ObjectId
. A possible workaround would be to try and create an ObjectId
instance, but leave the value as-is if it isn't valid. That way, the operation will either succeed (if such a record exists) or be a no-op (which would be the assumed behaviour for any batch that doesn't exist). As is, passing a string that isn't ObjectId
-like would result in an exception, which IMO is not desirable.
public function get($limit = 50, $before = null): array | ||
{ | ||
if (is_string($before)) { | ||
$before = new ObjectId($before); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beware that this may throw an exception if the string is not a well-formed ObjectId
. Not sure if that's something we want to consider, but I figured I'd point it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the store
method, the _id
is not set, so only ObjectId
can be inserted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to point this out as theoretically users could call the method with any string. No objection to assuming valid ObjectIDs are passed and leaving this as-is.
if (! isset($config['collection']) && isset($config['table'])) { | ||
trigger_error('Since mongodb/laravel-mongodb 4.4: Using "table" option for the queue is deprecated. Use "collection" instead.', E_USER_DEPRECATED); | ||
$config['collection'] = $config['table']; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgive me for any ignorant questions.
|
||
// Extending DatabaseBatchRepository is necessary so methods pruneUnfinished and pruneCancelled | ||
// are called by PruneBatchesCommand | ||
class MongoBatchRepository extends DatabaseBatchRepository implements PrunableBatchRepository |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason for inconsistent use of "Mongo" and "MongoDB" as class prefixes? This isn't the first time I've noticed it, and I understand that there may be historical inconsistencies in the project, but this PR introduces two new classes with inconsistent names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also named MongoLock
and MongoStore
with the same unsaid naming rule, following the naming examples of MongoConnector
, MongoQueue
...
$_SERVER['__progress.count']++; | ||
}) | ||
->then(function (Batch $batch) { | ||
$_SERVER['__then.batch'] = $batch; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would $this
be used here even if it was supported?
Offhand, is laravel/serializable-closure used internally for serialization? AFAIK, the stock serialize()
function doesn't support closures on its own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can decide which of my comments are worth addressing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few suggestions for the docs portion
Co-authored-by: Jordan Smith <45415425+jordan-smith721@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approving with comments, when this PR is merged I will make an edits PR!
@@ -38,7 +38,7 @@ the driver in ``config/queue.php``: | |||
- **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. | |||
- 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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. |
'queue' => 'default', | ||
'expire' => 60, | ||
'retry_after' => 60, | ||
], | ||
], | ||
|
There was a problem hiding this comment.
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:"
- 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- **Required**. Name of the MongoDB collection to store jobs to process. | |
- **Required**. Specifies the name of the MongoDB collection to store jobs to process. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applies to all entries
'database' => 'mongodb-job', | ||
'table' => 'failed_jobs', | ||
'database' => 'mongodb', | ||
'collection' => 'failed_jobs', | ||
], | ||
|
There was a problem hiding this comment.
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
Fix PHPORM-81
Checklist