I am trying to get a rails application together to replace the unreliable php monstrosity encoding. The current incarnation is pulling data from non-Rails db, pasting it into db Rails, and then displaying it in the views. Db is mostly filled with temperature readings that are added every few seconds. I can show a static page in Rails without problems, but trying to add ActionCable / realtime data was problematic. Everything seems to be working fine, but when I broadcast to my channel, it doesn't seem to get into the Received function in mychannel.coffee.
My setup: Server - Passenger (launch passenger launch) Job Search ActionCable - Redis
Data is imported from legacydb using a job that captures raw SQL and creates new records. After that, another task is broadcast on the channel.
The problems come from ActionCable, I think. It seems that all the examples that I can find require user input to run JS. However, I am trying to call things strictly from the server side. This job:
class DatabroadcastJob < ApplicationJob queue_as :default self.queue_adapter = :resque def perform ActionCable.server.broadcast 'dashboard_channel', content: render_thedata end private def render_thedata dataArr =[Data1.last, Data2.last, Data3.last] ApplicationController.renderer.render(partial: 'dashboard/data_tables', locals: {item: dataArr}) end end
Works. It is working. I see that the broadcast falls into the dashboard_channel panel. However, nothing in dashboard.coffee is broadcast. This is incredibly confusing.
Dashboard.coffee
App.dashboard = App.cable.subscriptions.create "DashboardChannel", connected: ->
Nothing happens. Logs show the broadcast, but nothing falls into the dashboard.coffee panel and triggers a warning in the browser. I think this is wrong because all the chat examples? Is there still a place where I receive the broadcast and push it to subscribers only when the server part changes?
If any other information is required to solve this problem, please let me know. This question made me think for several days.