Sidekiq perform_later无法使用Action Cable

时间:2016-08-12 00:18:57

标签: javascript ruby-on-rails websocket sidekiq actioncable

我在我的应用程序中设置了一个基本的动作有线电视聊天功能。我有一个after_create_commit回调函数,它将消息发送到要广播到相应频道的作业。当它设置为perform_now时它工作正常,但当它设置为perform_later时不起作用。 Sidekiq执行任务并向正确的频道广播,但频道订阅不会收到任何内容。

以下是正在设置的频道:

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"})

以下是传入并发送给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>>

这是sidekiq处理工作和广播到正确的渠道:

[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.org/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

但是频道实际上并没有得到任何数据。正如我所说的,当它设置为perform_now但在perform_later上进行borks时,这样可以正常工作。有什么想法吗?

2 个答案:

答案 0 :(得分:12)

我刚才有同样的问题。看起来它是由默认的cable.yml文件引起的,其设置如下:

development:
  adapter: async

test:
  adapter: async

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

但看起来异步适配器不能用于从单独的进程进行广播。要启用此功能,您可以将cable.yml文件修改为:

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

development:
  <<: *default

test:
  <<: *default

production:
  <<: *default

这也允许您从控制台广播。

答案 1 :(得分:0)

将sidekiq更新为4.2,它支持rails 5