Skip to content
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

Closed
wants to merge 14 commits into from

Conversation

Artistan
Copy link
Contributor

@Artistan Artistan commented Oct 6, 2017

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

Charles Peterson added 5 commits October 6, 2017 14:06
…he chain and can be changed at any time in the chain to persist from that point. Does not break or affect current functionality.
@Artistan
Copy link
Contributor Author

Artistan commented Oct 6, 2017

this could be rolled into 5.5 also, since it does not break the current functionality of the chained jobs.

@paulofreitas
Copy link
Contributor

paulofreitas commented Oct 7, 2017

@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 Illuminate\Bus\Queueable trait is used in every queue job created. If for whatever reason people overload the chain() method in the job class this would break existing applications. That said, this is fine for 5.6. 😃

$next->chained = $this->chained;
// use the chain setting if this job is not specifically set.
$next->onConnection($next->connection ?: $this->chain_connection);
Copy link
Member

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?

Copy link
Contributor Author

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.

@taylorotwell
Copy link
Member

Your formatting does not match the rest of the framework.

@Artistan
Copy link
Contributor Author

@taylorotwell - can you explain about the formatting please. I can refactor to be more consistent.

@@ -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
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor Author

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.

*
* @var string|null
*/
public $chain_connection = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use camelCase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Artistan
Copy link
Contributor Author

Updated formatting to be more consistent with the framework per @GrahamCampbell suggestions.

@@ -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))) {
Copy link
Contributor

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

@Artistan
Copy link
Contributor Author

updated per @jmarcher suggestions.

@Artistan
Copy link
Contributor Author

@GrahamCampbell - can you check your change requests

@@ -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 */
Copy link
Contributor

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

@@ -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))) {
Copy link
Contributor

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?

Copy link
Contributor Author

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;
            }));
        }
    }

Copy link
Contributor Author

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.

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...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this comment

// 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...
Copy link
Contributor

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

$next->chained = $this->chained;
// use the chain setting if this job is not specifically set.
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use camel case here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot this one

Copy link
Contributor

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;
Copy link
Contributor

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)
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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

@Artistan
Copy link
Contributor Author

updated again, Not sure why @GrahamCampbell review is still there.

@jmarcher
Copy link
Contributor

I can not see any of the changes I requested

@Artistan
Copy link
Contributor Author

@jmarcher -- this should be everything you mentioned.
ec8c3ab

@Artistan
Copy link
Contributor Author

@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');
}
Copy link
Member

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.

@taylorotwell
Copy link
Member

There is still a lot of bad formatting in this. @themsaid maybe you can take a shot at supporting this stuff.

@themsaid
Copy link
Member

@taylorotwell here's my attempt on this: #21765

@Artistan
Copy link
Contributor Author

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 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants