javascript - Sidekiq perform_later 不适用于 Action 电缆

标签 javascript ruby-on-rails websocket sidekiq actioncable

我在我的应用程序中设置了一个基本的行动电缆供电聊天。我有一个 after_create_commit 回调,它将消息发送到要广播到适当 channel 的作业。当它设置为 perform_now 时它工作正常,但当它设置为 perform_later 时它不起作用。 Sidekiq 执行任务并广播到正确的 channel ,但 channel 订阅没有收到任何内容。

这是正在设置的 channel :

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 处理作业并广播到正确的 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.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

但是 channel 实际上并没有得到任何数据。正如我所说,当它设置为 perform_now 但在 perform_later 上失败时,它可以正常工作。有任何想法吗?

最佳答案

我刚遇到同样的问题。貌似是默认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

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

关于javascript - Sidekiq perform_later 不适用于 Action 电缆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38908012/

相关文章:

javascript - console.log 会阻止垃圾收集吗?

javascript - JSON 无效 token

python - 使用 Django Channels 将信息发送到所有连接的客户端

php - Laravel 是否存在类似 Rails Engine 的东西?

ruby-on-rails - Rails-如何在searchkick中添加更多字段以进行过滤?

mysql - Sphinx 可以匹配与所提供的搜索参数相似的术语或短语吗?

java - 我可以将 Socket.io 与 Spring-boot 一起使用吗?

javascript - 无法设置 Highstock (Highcharts) 的 xAxis min

javascript - 如何在饼图上正确绘制文本?

javascript - 前瞻断言 JavaScript