laravel / horizon

Dashboard and code-driven configuration for Laravel queues.
https://laravel.com/docs/horizon
MIT License
3.87k stars 656 forks source link

Can't "pick up" a pending job from redis subscribe #1178

Closed deviddev closed 2 years ago

deviddev commented 2 years ago

Description:

I'm trying to dispatch (broadcast) an event from artisan command that handle redis subscriber (pub-sub). The event was passed to horizon/queue (redis) and its pending but never processed (any other jobs or broadcast are processed). If I dispatch that event "outside" from Redis::subscribe or in Redis::subscribe but with implemented SholdBroadcastNow interface its processed successfully.

just-pending

Steps To Reproduce:

RedisSubscribeCommand.php

class RedisSubscribe extends Command
{

    protected $signature = 'redis:subscribe';

    protected $description = 'Subscribe to a Redis channel';

    public function handle()
    {
        Redis::subscribe(['test-channel'], function ($message) {
            broadcast(new RecognizeBusEvent('test'));
        });
    }
}

TestEvent.php

// when imeplement ShouldBroadcastNow it works
// with ShouldBroadcast also dispatched to queue, but it just pending
class RecognizeBusEvent implements ShouldBroadcast 
{
    use Dispatchable, InteractsWithSockets;

    public function __construct(
        public $message
    ) {
        //
    }

    public function broadcastOn()
    {
        return new Channel('test');
    }

    public function broadcastWith()
    {
        return [
            'message' => $this->message
        ];
    }
}
driesvints commented 2 years ago

Hey there,

Can you first please try one of the support channels below? If you can actually identify this as a bug, feel free to open up a new issue with a link to the original one and we'll gladly help you out.

Thanks!