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
PHPORM-81 implement mongodb
driver for batch
#2904
base: 4.4
Are you sure you want to change the base?
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
...
@@ -51,6 +54,15 @@ protected function registerFailedJobServices() | |||
*/ | |||
protected function mongoFailedJobProvider(array $config): MongoFailedJobProvider | |||
{ | |||
return new MongoFailedJobProvider($this->app['db'], $config['database'], $config['table']); | |||
if (! isset($config['collection']) && isset($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.
Should it be an outright exception to specify both table
and collection
? As-is, I assume table
would just be ignored.
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.
Yes, table
will be ignored if collection
is set. Allowing both make migration easier as you can specify both during transition.
$_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.
@@ -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` |
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.
Do you also need to note deprecating expire
for retry_after
?
#[Override] | ||
public function transaction(Closure $callback): mixed | ||
{ | ||
return $this->connection->transaction(fn () => $callback()); |
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 significance to wrapping $callback
in an additional closure?
Fix PHPORM-81
Checklist