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.5+] Non Documented Breaking Change on dispatch() helper #23866

Closed
dbpolito opened this issue Apr 12, 2018 · 2 comments
Closed

[5.5+] Non Documented Breaking Change on dispatch() helper #23866

dbpolito opened this issue Apr 12, 2018 · 2 comments

Comments

@dbpolito
Copy link
Contributor

  • Laravel Version: 5.5+
  • PHP Version: irrelevant
  • Database Driver & Version: irrelevant

Description:

The behavior changed here: 91f5357#diff-12ace36c0bee81cc87f38273d5fe2a07R376

The previous behavior, it was directly calling app(Dispatcher::class)->dispatch($this->job);, which if you are using the Database Queue Driver, it returns the id of the jobs table. (not sure about other drivers).

Now it's creating a PendingDispatch object, which only dispatches the job on __destruct (https://github.com/laravel/framework/blob/5.6/src/Illuminate/Foundation/Bus/PendingDispatch.php#L110-L113), so no way for getting the id from the jobs table using this helper anymore.

I thought about adding a way for early dispatching it, something like:

src/Illuminate/Foundation/Bus/PendingDispatch.php

    /**
     * Dispatches the job.
     *
     * @return mixed
     */
    public function dispatch()
    {
        if (! $this->dispatched) {
            $this->dispatched = true;

            return app(Dispatcher::class)->dispatch($this->job);
        }
    }

    /**
     * Handle the object's destruction.
     *
     * @return void
     */
    public function __destruct()
    {
        $this->dispatch();
    }

But not sure it's a good solution... for now i'm going to call app(Dispatcher::class)->dispatch($job) directly on my code.

Another option would be add a second param here: https://github.com/laravel/framework/blob/5.6/src/Illuminate/Foundation/helpers.php#L381-L385

Like, $pending = true, or something like that.

@devcircus
Copy link
Contributor

Documented in the 5.5 upgrade guide :

The dispatch Helper

If you would like to dispatch a job that runs immediately and returns a value from the handle method, you should use the dispatch_now or Bus::dispatchNow method to dispatch the job:

use Illuminate\Support\Facades\Bus;

$value = dispatch_now(new Job);

$value = Bus::dispatchNow(new Job);

There's also been several dispatchNow helpers added since, to make things even more simple.

@dbpolito
Copy link
Contributor Author

Well, i saw this one but it's not very clear, and the old dispatch() doesn't do the same thing as dispatch_now(), different things.

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

No branches or pull requests

3 participants