【问题标题】:Rails jobs stuck for sidekiq error broken pipeline using mqttRails 作业因使用 mqtt 的 sidekiq 错误损坏管道而卡住
【发布时间】:2021-01-17 06:15:34
【问题描述】:

Sidekiq 尝试处理 Rails 作业时出错。 我现在正在将网络应用程序迁移到谷歌云服务,在那里我设置了一个 redis 服务器和代理 mqtt。

活动作业如下:

 def publish_update
topic = "tournament_team_category/#{@round_match.round.tournament_team_category.id}"
payload = {
  round_match: {
    id: @round_match.id,
    started_at: @round_match.started_at,
    ended_at: @round_match.ended_at,
    first_round_match_team: {
      id: @round_match.first_round_match_team.id,
      goals: @round_match.first_round_match_team.goals
    },
    second_round_match_team: {
      id: @round_match.second_round_match_team.id,
      goals: @round_match.second_round_match_team.goals
    }
  }
}

# TODO: Improve exception manage
begin
  MQTT_CLIENT.connect
  MQTT_CLIENT.publish(topic, payload.to_json, false, 1)
  MQTT_CLIENT.disconnect
rescue MQTT::NotConnectedException => _e
  return nil
rescue MQTT::ProtocolException => _e
  return nil
end
end

当 Sidekiq 尝试执行此作业时,服务器向我显示此错误:

2020-10-01 13:22:39 worker[20201001t140958]  2020-10-01T13:22:39.897Z 1 TID-gtixo1hip WARN: Errno::EPIPE: Broken pipe
2020-10-01 13:22:39 worker[20201001t140958]  2020-10-01T13:22:39.897Z 1 TID-gtixo1hip WARN: /app/vendor/bundle/ruby/2.6.0/gems/mqtt-0.5.0/lib/mqtt/client.rb:556:in `write'
2020-10-01 13:22:39 worker[20201001t140958]  /app/vendor/bundle/ruby/2.6.0/gems/mqtt-0.5.0/lib/mqtt/client.rb:556:in `block in send_packet'

mqtt client.rb 556行代码为:

# Send a packet to server
   def send_packet(data)
# Raise exception if we aren't connected
   raise MQTT::NotConnectedException if not connected?

# Only allow one thread to write to socket at a time
   @write_semaphore.synchronize do
   @socket.write(data.to_s)
 end
end

我找不到任何解决方案来解决这个问题,而且我的工作仍然陷入困境。 有人遇到过这种问题吗?

谢谢

【问题讨论】:

    标签: ruby-on-rails redis mqtt sidekiq


    【解决方案1】:

    看起来您的 MQTT 客户端使用不是线程安全的,您需要这个:

    https://github.com/mperham/sidekiq/wiki/Advanced-Options#connection-pooling

    【讨论】:

    • 谢谢,我对 sidekiq 高级选项不太熟练。据我了解,我必须为 sidekiq 生成一个单独的工作人员,对吗?你能帮我用我的代码设置它吗?
    猜你喜欢
    • 1970-01-01
    • 2012-12-07
    • 1970-01-01
    • 2016-07-21
    • 2014-04-28
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 2015-07-13
    相关资源
    最近更新 更多