admin管理员组

文章数量:1346070

I've set up a basic action cable powered chat in my application. I have an after_create_mit callback that sends the message to a job to be broadcast to the appropriate channel. It works fine when it's set to perform_now, but doesn't work when it's set to perform_later. Sidekiq performs the task and broadcasts to the right channel, but the channel subscription does not receive anything.

Here is the channel being set up:

PodsChannel is transmitting the subscription confirmation
PodsChannel is streaming from pods_channel_310
PodsChannel#speak({"message"=>"word", "pod_slug"=>"310", "user_id"=>"1", "msg_type"=>"pod_message"})

Here is the message ing in and being sent to sidekiq:

[ActiveJob] Enqueued MessageBroadcastJob (Job ID: c9cc59ce-2202-400d-92fb-15b80a9ece67) to Sidekiq(development_default) with arguments: #<GlobalID:0x007fa2e63526a0 @uri=#<URI::GID gid://sutra/PodMessage/1390>>

And here is sidekiq processing the job and broadcasting to the right channel:

[ActiveJob] [MessageBroadcastJob] [546222f6-9a57-493d-a3bb-b4886e0ad708]   Rendered pod_messages/_pod_message.html.erb (61.0ms)
[ActiveJob] [MessageBroadcastJob] [546222f6-9a57-493d-a3bb-b4886e0ad708] [ActionCable] Broadcasting to pods_channel_310: {:message=>"<div class='msg-wrap' id='msg_1389'><div class='msg-avatar'><a href=\"\"><img class=\"avatar-img\" alt=\"Lorenz\" src=\"/uploads/user/avatar/1/thumb_Lorenz2-square.jpg\" /></a></div><div class='msg-details'><div class='msg-meta'><div class='msg-sender'>Lorenz</div><div class='msg-timestamp'>Friday, August 12 at 12:09 AM</div><div class='msg-delete'><a data-remote=\"true\" rel=\"nofollow\" data-method=\"delete\" href=\"/delete_pod_message/1389\"><span class='glyphicon glyphicon-remove-circle' aria-hidden='true'></span></a></div></div><div class='msg-text'>word</div></div></div>\n"}
[ActiveJob] [MessageBroadcastJob] [546222f6-9a57-493d-a3bb-b4886e0ad708] Performed MessageBroadcastJob from Sidekiq(development_default) in 143.57ms

But then the channel doesn't actually get any data. As I said, this works fine when it's set to perform_now but borks on perform_later. Any ideas?

I've set up a basic action cable powered chat in my application. I have an after_create_mit callback that sends the message to a job to be broadcast to the appropriate channel. It works fine when it's set to perform_now, but doesn't work when it's set to perform_later. Sidekiq performs the task and broadcasts to the right channel, but the channel subscription does not receive anything.

Here is the channel being set up:

PodsChannel is transmitting the subscription confirmation
PodsChannel is streaming from pods_channel_310
PodsChannel#speak({"message"=>"word", "pod_slug"=>"310", "user_id"=>"1", "msg_type"=>"pod_message"})

Here is the message ing in and being sent to sidekiq:

[ActiveJob] Enqueued MessageBroadcastJob (Job ID: c9cc59ce-2202-400d-92fb-15b80a9ece67) to Sidekiq(development_default) with arguments: #<GlobalID:0x007fa2e63526a0 @uri=#<URI::GID gid://sutra/PodMessage/1390>>

And here is sidekiq processing the job and broadcasting to the right channel:

[ActiveJob] [MessageBroadcastJob] [546222f6-9a57-493d-a3bb-b4886e0ad708]   Rendered pod_messages/_pod_message.html.erb (61.0ms)
[ActiveJob] [MessageBroadcastJob] [546222f6-9a57-493d-a3bb-b4886e0ad708] [ActionCable] Broadcasting to pods_channel_310: {:message=>"<div class='msg-wrap' id='msg_1389'><div class='msg-avatar'><a href=\"http://example/lorenzsell\"><img class=\"avatar-img\" alt=\"Lorenz\" src=\"/uploads/user/avatar/1/thumb_Lorenz2-square.jpg\" /></a></div><div class='msg-details'><div class='msg-meta'><div class='msg-sender'>Lorenz</div><div class='msg-timestamp'>Friday, August 12 at 12:09 AM</div><div class='msg-delete'><a data-remote=\"true\" rel=\"nofollow\" data-method=\"delete\" href=\"/delete_pod_message/1389\"><span class='glyphicon glyphicon-remove-circle' aria-hidden='true'></span></a></div></div><div class='msg-text'>word</div></div></div>\n"}
[ActiveJob] [MessageBroadcastJob] [546222f6-9a57-493d-a3bb-b4886e0ad708] Performed MessageBroadcastJob from Sidekiq(development_default) in 143.57ms

But then the channel doesn't actually get any data. As I said, this works fine when it's set to perform_now but borks on perform_later. Any ideas?

Share Improve this question asked Aug 12, 2016 at 0:18 LorenzLorenz 7751 gold badge7 silver badges28 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 14

I just had this same issue. It looks like it is caused by the default cable.yml file which is setup like:

development:
  adapter: async

test:
  adapter: async

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

But it looks like the async adapter cannot be used for broadcasting from separate processes. To enable this you can modify your cable.yml file to be:

default: &default
adapter: redis
url: redis://localhost:6379/1

development:
  <<: *default

test:
  <<: *default

production:
  <<: *default

This will also allow you to broadcast from the console as well.

Update sidekiq to 4.2, it supports rails 5

本文标签: javascriptSidekiq performlater not working with Action CableStack Overflow