-
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.6] Chained queue name and connection settings. #21568
Conversation
…he chain and can be changed at any time in the chain to persist from that point. Does not break or affect current functionality.
this could be rolled into 5.5 also, since it does not break the current functionality of the chained jobs. |
@Artistan Rolling to 5.5 branch would be a BC break. Every method signature change of a contract or inheritable class/trait are a potential BC break. Look, for example, that the |
src/Illuminate/Bus/Queueable.php
Outdated
$next->chained = $this->chained; | ||
// use the chain setting if this job is not specifically set. | ||
$next->onConnection($next->connection ?: $this->chain_connection); |
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 said this doesn't change existing behavior but this appears to do so. Why are you using the chain connection 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.
The default chain_connection is null. So is the next job connection.
If you set the chain connection, then the next job should use it as its connection if is it not specifically set on that job. I wrote test cases for these things also.
Your formatting does not match the rest of the framework. |
@taylorotwell - can you explain about the formatting please. I can refactor to be more consistent. |
src/Illuminate/Bus/Queueable.php
Outdated
@@ -74,14 +88,45 @@ public function delay($delay) | |||
/** | |||
* Set the jobs that should run if this job is successful. | |||
* | |||
* @param array $chain | |||
* @param $chain | |||
* @param null $queue |
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.
This doc is not correct I'm afraid. This says that you can only pass null
through.
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.
done
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.
@GrahamCampbell - can you approve this change review please.
src/Illuminate/Bus/Queueable.php
Outdated
* | ||
* @var string|null | ||
*/ | ||
public $chain_connection = null; |
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.
Please use camelCase.
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.
done
Updated formatting to be more consistent with the framework per @GrahamCampbell suggestions. |
src/Illuminate/Bus/Queueable.php
Outdated
@@ -95,7 +140,19 @@ public function dispatchNextJobInChain() | |||
{ | |||
if (! empty($this->chained)) { | |||
dispatch(tap(unserialize(array_shift($this->chained)), function ($next) { | |||
if (in_array('Illuminate\Bus\Queueable', class_uses_recursive($next))) { |
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 think is better to negate this condition than having an empty if body
updated per @jmarcher suggestions. |
@GrahamCampbell - can you check your change requests |
src/Illuminate/Bus/Queueable.php
Outdated
@@ -95,7 +140,18 @@ public function dispatchNextJobInChain() | |||
{ | |||
if (! empty($this->chained)) { | |||
dispatch(tap(unserialize(array_shift($this->chained)), function ($next) { | |||
/* @var \Illuminate\Bus\Queueable $next */ |
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.
This comment can be removed
src/Illuminate/Bus/Queueable.php
Outdated
@@ -95,7 +140,18 @@ public function dispatchNextJobInChain() | |||
{ | |||
if (! empty($this->chained)) { | |||
dispatch(tap(unserialize(array_shift($this->chained)), function ($next) { | |||
/* @var \Illuminate\Bus\Queueable $next */ | |||
if (! in_array('Illuminate\Bus\Queueable', class_uses_recursive($next))) { |
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 this check be checking if Illuminate\Contracts\Queue\ShouldQueue is implemented?
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.
not sure. should it check both?
here is the 5.5 current ....
/**
* Dispatch the next job on the chain.
*
* @return void
*/
public function dispatchNextJobInChain()
{
if (! empty($this->chained)) {
dispatch(tap(unserialize(array_shift($this->chained)), function ($next) {
$next->chained = $this->chained;
}));
}
}
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 suppose it could check on the chain method also, so it would not allow adding non-Queueable jobs to the chain.
Originally i added it because I had a test fail without much warning.
src/Illuminate/Bus/Queueable.php
Outdated
if (! in_array('Illuminate\Bus\Queueable', class_uses_recursive($next))) { | ||
throw new \Exception('Trying to dispatch an object that is not Queueable'); | ||
} | ||
// pass the chain settings on to the next job in the chain, IF this job does not have a new chain settings set... |
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.
Remove this comment
src/Illuminate/Bus/Queueable.php
Outdated
// pass the chain settings on to the next job in the chain, IF this job does not have a new chain settings set... | ||
$next->onChainConnection($next->chainConnection ?: $this->chainConnection); | ||
$next->onChainQueue($next->chainQueue ?: $this->chainQueue); | ||
// array of remaining 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.
This comment is also useless
src/Illuminate/Bus/Queueable.php
Outdated
$next->chained = $this->chained; | ||
// use the chain setting if this job is not specifically set. |
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.
Remove this comment it says the same as the code
* @return \Illuminate\Foundation\Bus\PendingChain | ||
*/ | ||
public static function withChain($chain) | ||
public static function withChain(array $chain, string $chain_queue = null, string $chain_connection = null) |
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.
Use Camel Case for method parameters
* @return void | ||
*/ | ||
public function __construct($class, $chain) | ||
public function __construct($class, $chain, $chain_queue = null, $chain_connection = null) |
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.
Use camel case for method parameters
* | ||
* @var string|null | ||
*/ | ||
public $chain_queue = null; |
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.
Use camel case 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.
You forgot this one
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.
Here as well initialization not needed
* | ||
* @var string|null | ||
*/ | ||
public $chain_connection = null; |
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.
Use camel case here
* @return \Illuminate\Foundation\Bus\PendingChain | ||
*/ | ||
public static function withChain($chain) | ||
public static function withChain(array $chain, string $chainQueue = null, string $chainConnection = null) |
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.
Remove type hint, this won't work
* | ||
* @var string|null | ||
*/ | ||
public $chain_queue = null; |
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 forgot this one
* | ||
* @var string|null | ||
*/ | ||
public $chainConnection = null; |
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.
Initialization not needed
* | ||
* @var string|null | ||
*/ | ||
public $chain_queue = null; |
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.
Here as well initialization not needed
updated again, Not sure why @GrahamCampbell review is still there. |
I can not see any of the changes I requested |
@jmarcher -- additional commits added from your latest reviews. :) thanks! |
@@ -95,7 +140,14 @@ public function dispatchNextJobInChain() | |||
{ | |||
if (! empty($this->chained)) { | |||
dispatch(tap(unserialize(array_shift($this->chained)), function ($next) { | |||
if (! in_array('Illuminate\Bus\Queueable', class_uses_recursive($next))) { | |||
throw new \Exception('Trying to dispatch an object that is not Queueable'); | |||
} |
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 don't understand why this is here. It should be removed. If the methods don't exist, we will get an error anyways.
There is still a lot of bad formatting in this. @themsaid maybe you can take a shot at supporting this stuff. |
@taylorotwell here's my attempt on this: #21765 |
I would greatly appreciate someone could explain "bad formatting" someday. Seems to be more of a preference in naming? Thanks for all the feedback. I hope @themsaid can finish off the feature with good formatting 😁 |
Allow managing chain queue an connections that will persist through the chain and can be changed at any time in the chain to persist from that point. Does not break or affect current functionality.
#21528