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

[8.x] Enexpected withChain(...) behaviour #35041

Closed
hivokas opened this issue Oct 31, 2020 · 3 comments · Fixed by #35047
Closed

[8.x] Enexpected withChain(...) behaviour #35041

hivokas opened this issue Oct 31, 2020 · 3 comments · Fixed by #35047
Labels

Comments

@hivokas
Copy link
Contributor

hivokas commented Oct 31, 2020

  • Laravel Version: 8.12.3
  • PHP Version: 7.4.11
  • Database Driver & Version: mysql Ver 8.0.19 for macos10.15 on x86_64 (MySQL Community Server - GPL)

Description:

There are 3 classes:

Base job

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;

abstract class BaseJob
{
    use Queueable;
}

JobHigh that should be processed in the high queue

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class JobHigh extends BaseJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, SerializesModels;

    public $queue = 'high';

    public function handle()
    {
        //
    }
}

JobMedium that should be processed in the medium queue

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class JobMedium extends BaseJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, SerializesModels;

    public $queue = 'medium';

    public function handle()
    {
        //
    }
}

While in Laravel 7 (7.28.4) both dispatch(new JobHigh); dispatch(new JobMedium); and JobHigh::withChain(new JobMedium)->dispatch() throw jobs to the appropriate queues, in Laravel 8 (8.12.3) that's not a case for withChain(...).

Is that a bug? Or that's a change that was accidentally not included Upgrade Guide.

Steps To Reproduce:

dispatch(new JobHigh);

dispatch(new JobMedium);

Laravel 7:

image

Laravel 8:

image

JobHigh::withChain([
    new JobMedium,
])->dispatch();

Laravel 7:

image

Laravel 8:

image

@hivokas
Copy link
Contributor Author

hivokas commented Oct 31, 2020

Looks like the problem lays here:

public function dispatch()
{
if (is_string($this->job)) {
$firstJob = new $this->job(...func_get_args());
} elseif ($this->job instanceof Closure) {
$firstJob = CallQueuedClosure::create($this->job);
} else {
$firstJob = $this->job;
}
$firstJob->allOnConnection($this->connection);
$firstJob->allOnQueue($this->queue);
$firstJob->chain($this->chain);
$firstJob->delay($this->delay);
$firstJob->chainCatchCallbacks = $this->catchCallbacks();
return app(Dispatcher::class)->dispatch($firstJob);
}

Here we are force-overriding the queue even if it was not specified (like here: JobHigh::withChain(new JobMedium)->onQueue('low')->dispatch()):

$firstJob->allOnConnection($this->connection); 
$firstJob->allOnQueue($this->queue); 

Should we do something like that?

if ($this->connection !== null) {
    $firstJob->allOnConnection($this->connection);
}

if ($this->queue !== null) {
    $firstJob->allOnQueue($this->queue);
}

@taylorotwell
Copy link
Member

@themsaid

@themsaid
Copy link
Member

themsaid commented Nov 1, 2020

Opened #35047 with a fix

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

Successfully merging a pull request may close this issue.

4 participants