【发布时间】: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