4
我在我的項目中使用pubnub,它訂閱了一個頻道,並在我的訂閱者更新我的數據庫。 我做這一切工作在初始化文件中像這樣異常:ActiveRecord :: ConnectionNotE建立使用pubnub
$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。但是有時這些代碼執行沒有問題。
我試圖增加數據庫超時和池,但同樣的問題仍然存在。 任何想法我做錯了?
有了這個我的代碼在開發中工作正常,但在生產模式下的服務器上,它在每種情況下拋出相同的錯誤。 –