Ruby 异常:ActiveRecord::ConnectionNote已在使用pubnub时建立
我在我的项目中使用pubnub,它订阅了一个频道,我在订阅服务器中更新了数据库。 我在这样一个初始化文件中做所有这些工作Ruby 异常:ActiveRecord::ConnectionNote已在使用pubnub时建立,ruby,ruby-on-rails-4,activerecord,mysql2,pubnub,Ruby,Ruby On Rails 4,Activerecord,Mysql2,Pubnub,我在我的项目中使用pubnub,它订阅了一个频道,我在订阅服务器中更新了数据库。 我在这样一个初始化文件中做所有这些工作 $callback_location = (lambda do |envelop| begin case envelop.channel when "iwm_driver_locations" last_location = LatLong.where(driver_id: envelop.message['driver_id']).l
$callback_location = (lambda do |envelop|
begin
case envelop.channel
when "iwm_driver_locations"
last_location = LatLong.where(driver_id: envelop.message['driver_id']).last
if last_location.lat != envelop.message['lng'] and last_location.lng != envelop.message['lat']
l = LatLong.create!(
lat: envelop.message['lat'],
lng: envelop.message['lng'],
driver_id: envelop.message['driver_id']
)
end
when "iwm_chat"
m = Message.create!(
:author => envelop.message,
:message => envelop.message,
:timetoken => envelop.timetoken
)
end
rescue Exception => e
Rails.logger.info "****** Exception: #{e}"
end
end)
$pubnub.subscribe(
:channel => ['iwm_chat', 'iwm_driver_locations'],
:callback => $callback_location
) unless $pubnub.subscription_running?
但我的订户在某些尝试中抛出异常ConnectionNotEstablished。但是,有时此代码执行时不会出现问题
我试图增加数据库超时和池,但同样的问题仍然存在。
知道我哪里做错了吗?尝试添加
ActiveRecord::Base。在启动$pubnub.subscribe
之前建立连接。这应该有帮助。我的代码在开发中运行良好,但在生产模式下的服务器上,在任何情况下都会抛出相同的错误。