-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[5.7] Transactional jobs #26515
[5.7] Transactional jobs #26515
Conversation
}; | ||
|
||
if ($this->instance instanceof Transactional) { | ||
$handler = function () use ($handler) { |
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.
TBH this style is freaking me out: "use"ing a variable and overwriting it in the same scope so the final call to it is the same? => That's a bit too much magic for my taste
|
||
if ($this->instance instanceof Transactional) { | ||
$handler = function () use ($handler) { | ||
$connection = method_exists($this->instance, 'dbConnection') && \is_callable([$this->instance, 'dbConnection']) |
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 can we, except with documentation, better indicate to developers that this dbConnection
method is possible to use?
The interface doesn't indicate it.
Also I'd like to see the naming a bit improved. E.g. getConnectionForTransaction
or something, otherwise it's ambiguous.
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.
https://github.com/laravel/framework/blob/5.7/src/Illuminate/Queue/Jobs/Job.php#L171
https://github.com/laravel/framework/blob/5.7/src/Illuminate/Bus/Dispatcher.php#L156
https://github.com/laravel/framework/blob/5.7/src/Illuminate/Queue/Queue.php#L151
https://github.com/laravel/framework/blob/5.7/src/Illuminate/Queue/Queue.php#L163
https://github.com/laravel/framework/blob/5.7/src/Illuminate/Broadcasting/BroadcastEvent.php#L43
https://github.com/laravel/framework/blob/5.7/src/Illuminate/Broadcasting/BroadcastEvent.php#L60
https://github.com/laravel/framework/blob/5.7/src/Illuminate/Broadcasting/BroadcastManager.php#L119
https://github.com/laravel/framework/blob/5.7/src/Illuminate/Foundation/Http/FormRequest.php#L150
What about interface for this and another ones?
|
||
$payload = $payloadFactory->invoke(new SyncQueue(), $jobClassname, null, ''); | ||
|
||
unset($_SERVER['0(*_*)0']); |
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.
Can we do better then working with a global variable here?
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.
Yep, job can use any payload, given from container mock to detect works.
But this is a simple test like Taylor have used here
It also can use real DB connection, real transactions. It's only base ones.
Honestly much simpler to just use |
Hello everyone, based on an existing package and with permission of its original author, I've drafted a possible solution to tackle the "transactional events" problem. At the moment it's a draft PR in my Laravel forked repo to first gather feedback from the community before approaching to create an official PR, to give things time to unfold / develop. I invite everyone to participate in mfn#1 and share your feedback. Thank you! |
@mfn think it's best that you actually send this in so people can give feedback. I doubt anyone will see it otherwise. |
Added
Transactional
jobs.With this PR we can easy to define that our job must execute in database transaction and it will automatically rollback if something will wrong.
Simple example:
And our data will still consistent event payout creation/balance changes will fail.
Probably, makes sense to add option like
-t|--transactional
to job generation command ?