ruby – 异常:ActiveRecord :: ConnectionNotEstablished使用pu
发布时间:2020-12-17 02:08:19 所属栏目:百科 来源:网络整理
导读:我在我的项目中使用pubnub并订阅了一个频道,在我的订阅者中我更新了我的数据库. 我正在这样的初始化文件中完成所有这些工作 $callback_location = (lambda do |envelop| begin case envelop.channel when "iwm_driver_locations" last_location = LatLong.wh
我在我的项目中使用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.但是,有时此代码执行时没有问题. 我试图增加数据库超时和池,但同样的问题仍然存在. 解决方法
尝试在触发$pubnub.subscribe之前添加ActiveRecord :: Base.establish_connection.它应该有所帮助.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |