skip to Main Content

I’ve some mistake with a job that I try to dispatch when my Redis subscribe command receive a message.

I launch the Redis subscribe inside an "artisan console" command :

Redis::subscribe(['channel'], function ($message) {
      dipatch((new MyJob($message)
                  ->onQueue('default')
                  ->onConnection('redis'));
}

Job is created and I can see it on my Laravel Horizon dashboard. But it’s never processed… "handle" function is never called and the job stay in "pending" tab on Horizon.
But when I dispatch it from a tinker session, that’s work fine!

Maybe I have to call another artisan command to launch the job outside the redis subscribe function, but hope there is a better solution…

Any ideas?

2

Answers


  1. Chosen as BEST ANSWER

    Solution : create another connection on the database.php file for your Redis database (same params as the default one, just change the name, eg name it "subscribe"), so after that change, the code must look like this :

    $redis = Redis::connection('subscribe'); 
    $redis->subscribe(['channel'], function () {});
    

  2. I had the same problem, The job will never be dispatched on Redis queue. When I used another queue driver (database or beanstalkd) it worked fine.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search