Framework: Unresolvable dependency in Illuminate\Queue\Worker

Created on 25 Aug 2019  路  11Comments  路  Source: laravel/framework

  • Laravel Version: 6.0
  • PHP Version: 7.3.1
  • Database Driver & Version: mysql Ver 15.1 Distrib 10.3.12-MariaDB

Description:

Unresolvable dependency when after upgrade from 5.8 to 6.0 in Illuminate\Queue\Worker with parameter 3 $isDownForMaintenance

Tried clearing compiled cache and retrying composer dump-autoload but not joy.

禄 composer dump-autoload -v                                                                                        [15:12 @ Sun 25 Aug 2019]
Generating optimized autoload files> post-autoload-dump: Illuminate\Foundation\ComposerScripts::postAutoloadDump
> post-autoload-dump: @php artisan package:discover

   Illuminate\Contracts\Container\BindingResolutionException  : Unresolvable dependency resolving [Parameter #3 [ <required> callable $isDownForMaintenance ]] in class Illuminate\Queue\Worker

  at /Users/jasonmorton/Beegap/vendor/laravel/framework/src/Illuminate/Container/Container.php:994
    990|     protected function unresolvablePrimitive(ReflectionParameter $parameter)
    991|     {
    992|         $message = "Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}";
    993|
  > 994|         throw new BindingResolutionException($message);
    995|     }
    996|
    997|     /**
    998|      * Register a new resolving callback.

  Exception trace:

  1   Illuminate\Container\Container::unresolvablePrimitive(Object(ReflectionParameter))
      /Users/jasonmorton/Beegap/vendor/laravel/framework/src/Illuminate/Container/Container.php:932

  2   Illuminate\Container\Container::resolvePrimitive(Object(ReflectionParameter))
      /Users/jasonmorton/Beegap/vendor/laravel/framework/src/Illuminate/Container/Container.php:873

  Please use the argument -v to see more details.
Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1

Steps To Reproduce:

Followed upgrade guide from laravel.com documentation - 5.8 - 6.0

Most helpful comment

We fixed this for Horizon last week and will do a release tomorrow which you can pull in. Try with 3.0-dev for now

All 11 comments

Unless you made your own container binding for the Worker class in your app I don't see how this doesn't work.

The $isDownForMaintenance parameter is bound here:

https://github.com/laravel/framework/blob/6.0/src/Illuminate/Queue/QueueServiceProvider.php#L161

If you have created your own binding for the Worker class you should update it for 6.0 to also pass the $isDownForMaintenance parameter which was added for the 6.0 release (https://github.com/laravel/framework/pull/29224)

I have this same issue and I am absolutely not rebinding the queue worker class

No, I'm definitely note rebinding the Worker class. Something else must be going on.

@JasonMortonNZ Would you be able to share your composer dependencies? Might help to compare and see if we're ve got any overlap that might be causing the issue.

Looks like it's Horizon causing it. Getting rid of my Horizon dependency fixed the issue.

We fixed this for Horizon last week and will do a release tomorrow which you can pull in. Try with 3.0-dev for now

@driesvints is this issue really solved? I use last version of horizon and I still have the same problem. The commit related to solve this probles is https://github.com/laravel/horizon/commit/3b533104caa299761ce6a1c41438bdab1e2e246f ?

@acacha yeah. I can run Horizon with that change.

Just come across this issue. For me the actual issue was that I had a class injecting the queue worker via type hinting of Illuminate\Queue\Worker. The best way to resolve is to either set up an alias of the class to the container item queue.worker or just set up the dependency of the item you want and to inject queue.worker in it's creation.

@peterfox I'm still stuck with this issue. I'm sorry I think I don't understand the problem. Could you provide and example or elaborate your solution?

Ok I found a solution:

Previously to Laravel 6.0 I have extended/modified queue:worker command with:

 $this->app->extend('command.queue.work', function () {
//            return new WorkCommand(app('queue.worker'),app('cache.store'));
//        });

In boot method boot() of my AppServiceProvider. Now I have to remove this lines and put on register() method:

$this->app->bind(WorkCommand::class, function ($app) {
            return new WorkCommand($app['queue.worker'], $app['cache.store']);
        });

Where WorkCommand is my custom command.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RomainSauvaire picture RomainSauvaire  路  3Comments

JamborJan picture JamborJan  路  3Comments

shopblocks picture shopblocks  路  3Comments

PhiloNL picture PhiloNL  路  3Comments

digirew picture digirew  路  3Comments