0

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?

xelab
  • 31
  • 5

2 Answers2

3

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 () {});
xelab
  • 31
  • 5
0

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.

Joundill
  • 6,828
  • 12
  • 36
  • 50
  • I found the solution, It was here too (but not confirmed) : https://stackoverflow.com/questions/32282136/unable-to-fire-a-laravel-event-from-within-a-laravel-redis-pub-sub-subscriber You have to 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 this you'll do like this : $redis = Redis::connection('subscribe'); $redis->subscribe(['channel'], function () {... – xelab Nov 26 '20 at 14:11
  • Deleted my answer as it was unrelated please describe your solution :) – mrhn Nov 26 '20 at 16:35
  • Yup, i can confirm @xelab solution works. I have to create dedicated connection for subscribing to Redis channel. – Wildan Ainurrahman Nov 27 '20 at 01:16