I use pubnub in my project and subscribe to the channel, and in my subscriber I update my database. I do all this work in an initialization file like this
$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?
but my subscriber throws ConnectionNotEstablished exception in some attempts. However, sometimes this code runs without problems.
I tried to increase the timeout and database pool, but the same problem persists. Any idea where I am doing wrong?
source share