【问题标题】:Sidekiq current Celluloid ActorSidekiq 当前的赛璐珞演员
【发布时间】:2013-06-04 04:53:34
【问题描述】:

我需要访问我的 Sidekiq 工作人员中当前的赛璐珞演员,但我看不到这样做的方法。

每当我尝试打电话时:

Celluloid::Actor.current

我收到一个错误:not in actor scope

我试图通过每次都创建一个新演员来找到当前演员:

Celluloid::Actor.new(SecureRandom.hex)

但由于某种原因,它给了我一个 attempted to call dead actor 的错误。

我应该做些什么不同的事情来让当前的演员进入 Sidekiq 工作人员?

背景信息 我正在连接到我的工作人员中的 websocket 并向其发送消息。

Celluloid::WebSocket::Client.new('ws://my-uri', Celluloid::Actor.current)

【问题讨论】:

  • 为什么需要这样做?
  • 好问题,我认为这与问题无关。但是我正在连接到我的工作人员中的 websocket 并向其发送消息。 @websocket_client ||= Celluloid::WebSocket::Client.new('ws://my-uri', Celluloid::Actor.current)
  • 您确定要使用工人吗?也许您只需要一个简单的守护进程?
  • 不幸的是,我确实需要使用工人。好主意!
  • 祝你好运。希望你能解决这个问题:)

标签: ruby sidekiq celluloid


【解决方案1】:

猜你应该定义一个单独的类,包括赛璐珞,这是一个基于one of those from Sidekiq repo的示例

class MyWebSocketWhatever
  include Celluloid

  def initialize(url)
    @ws_client = Celluloid::WebSocket::Client.new url, Celluloid::Actor.current
  end

  def send_message(msg)
    @ws_client.text msg
  end

  def on_message(msg)
    $redis.lpush 'sinkiq-example-messages', "RESPONSE: #{msg}"
  end
end

class SinatraWorker
  include Sidekiq::Worker

  def perform(msg='lulz you forgot a msg!')
    $redis.lpush 'sinkiq-example-messages', "SENT: #{msg}"
    MyWebSocketWhatever.new('ws://echo.websocket.org').send_message msg
  end
end    

就像一个魅力,刚刚玩完它。获取the full updated example,安装所需的gem,然后同时启动Sinatra 和Sidekiq

sidekiq -r ./sinkiq.rb
ruby ./sinkiq.rb

然后浏览到http://localhost:4567

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-02
    • 1970-01-01
    • 2012-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-07
    • 2016-01-31
    相关资源
    最近更新 更多