Sidekiq perform_later 不适用于 Action Cable [英] Sidekiq perform_later not working with Action Cable

查看:35
本文介绍了Sidekiq perform_later 不适用于 Action Cable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've set up a basic action cable powered chat in my application. I have an after_create_commit 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.

这是正在设置的频道:

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 的消息:

Here is the message coming 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>>

这里是 sidekiq 处理作业并广播到正确的频道:

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.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 时出错.有什么想法吗?

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?

推荐答案

我刚刚遇到了同样的问题.看起来它是由默认的 cable.yml 文件引起的,该文件设置如下:

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

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

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.

这篇关于Sidekiq perform_later 不适用于 Action Cable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆