Search code examples
ruby-on-railsruby-on-rails-5actioncablerescue

ActionCable not run in background job rails 5


My project use rescue to run background job. I use actioncable in a job to notify user when the job finish. but it not running when use perform_later, but perform_now => it work ok.

My job:

class FetchExternalDataJob < ApplicationJob
  queue_as :default

  def perform
    # logic here
    ActionCable.server.broadcast "some_channel", message: "finish job"
  end
end

Call job:

class RoomsController < ApplicationController

  def show
    FetchExternalDataJob.perform_later
  end

Channel javascript:

App.fetch_data = App.cable.subscriptions.create "FetchDataChannel",
  received: (data) ->
    console.log("job finished")

Solution

  • Have you set up redis as your adapter in cable.yml yet?

    ei:

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