Getting an Action Cable to Stream to Sidekiq Job

I use Rails 5 in a docker environment, and I can get Action Cable to broadcast to the Sidekiq desktop perfectly using worker.new.perform.

But for the life of me, I cannot get it to broadcast when using worker.perform_async.

Here is my cable.yml:

default: &default
 adapter: redis
 url: <%= ENV['REDIS_PROVIDER'] %>

development:
 <<: *default

test:
  <<: *default

production:
  <<: *default

Here is my worker:

class AdminWorker
  include Sidekiq::Worker

  def perform
    ActionCable.server.broadcast 'admin_channel', content: 'hello'
  end
 end

My Admin Channel:

class AdminChannel < ApplicationCable::Channel
 def subscribed
  stream_from "admin_channel"
 end

 def unsubscribed
  # Any cleanup needed when channel is unsubscribed
 end
end

As I mentioned earlier, this works fine when calling AdminWorker.new.perform. As soon as I try to run AdminWorker.perform_async, the cable will not be broadcast and nothing will help with respect to the cable's action in the logs. What am I missing here?

+7
source share
2 answers

. : ActionCable.server.broadcast - . cable.yml

development:
  adapter: async

to

development:
  adapter: redis
  url: redis://localhost:6379/1

, , Sidekiq ..

+15

Source: https://habr.com/ru/post/1670462/


All Articles