gpt4 book ai didi

ruby - 异常:ActiveRecord::ConnectionNotEstablished 使用 pubnub

转载 作者:太空宇宙 更新时间:2023-11-03 16:22:14 25 4
gpt4 key购买 nike

我在我的项目中使用 pubnub,它订阅了一个 channel ,在我的订阅者中我更新了我的数据库。我正在这样的初始化文件中完成所有这些工作

$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。它应该有所帮助。

关于ruby - 异常:ActiveRecord::ConnectionNotEstablished 使用 pubnub,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31784159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com