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

Invalid method in QueueTenancyBootstrapper #1266

Open
eskayamadeus opened this issue Nov 1, 2024 · 1 comment
Open

Invalid method in QueueTenancyBootstrapper #1266

eskayamadeus opened this issue Nov 1, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@eskayamadeus
Copy link

Bug description

The following lines of code in QueueTenancyBootstrapper.php appear to be invalid. When you use queue:work to run a queued job, the constructor of this class is called.

The constructor in turn calls $this->setUpPayloadGenerator().

The payload generator includes the code aforementioned:

protected function setUpPayloadGenerator()
    {
        $bootstrapper = &$this;
        
        if (! $this->queue instanceof QueueFake) {
            $this->queue->createPayloadUsing(function ($connection) use (&$bootstrapper) {
                // we never get here because the createPayloadUsing() method doesn't exist on `$this->queue` object. 
                // it exists on \Illuminate\Queue\Queue or \Illuminate\Support\Facades\Queue facade
                return $bootstrapper->getPayload($connection);
            });
        }
    }

The $this->queue->createPayloadUsing() closure is never executed because the createPayloadUsing() method doesn't exist on the $this->queue class.

In the constructor, we see that $this->queue is an instance of use Illuminate\Queue\QueueManager. This class does not have the createPayloadUsing() method. Instead, it is available on the Illuminate\Queue\Queue class as seen here.

Steps to reproduce

  • Install the Tenancy package.
  • In QueueTenancyBootstrapper, put dd('here') inside the closure at $this->queue->createPayloadUsing().
  • Dispatch a queued job or event inside your code, to be run in a tenant context.
  • Run php artisan queue:work
  • The dumped string will never output because the code never reaches that point.

Alternatively,

  • put get_class_methods($this->queue) on the line just after if (! $this->queue instanceof QueueFake).
  • run php artisan queue:work
  • a list of methods will be displayed but it will not include createPayloadUsing()

Expected behavior

The job should dispatch and execute when queue:work is used.

Laravel version

10.48.22

stancl/tenancy version

3.8.5

@eskayamadeus eskayamadeus added the bug Something isn't working label Nov 1, 2024
@stancl
Copy link
Member

stancl commented Nov 1, 2024

I don't really get this issue. Are you commenting on the implementation or reporting a bug? Say what doesn't work for you as expected.

The following lines of code in QueueTenancyBootstrapper.php appear to be invalid. When you use queue:work to run a queued job, the constructor of this class is called.

Pretty sure that's irrelevant. The code you're talking about affects payload creation, which happens before jobs are being processed by the queue worker. This logic running in queue:work doesn't really do anything.

The $this->queue->createPayloadUsing() closure is never executed because the createPayloadUsing() method doesn't exist on the $this->queue class.

That would throw an exception, not silently fail.

In the constructor, we see that $this->queue is an instance of use Illuminate\Queue\QueueManager. This class does not have the createPayloadUsing() method. Instead, it is available on the Illuminate\Queue\Queue class as seen here.

https://github.com/laravel/framework/blob/61e221c18a89780ed5b51b59f04c0b4c389a457d/src/Illuminate/Queue/QueueManager.php#L11

The dumped string will never output because the code never reaches that point

Again, the worker is not concerned with payload creation, it's reading already created payloads and executing them.

a list of methods will be displayed but it will not include createPayloadUsing()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants