从 Rails 中的线程进行活动记录事务时抛出异常
我在从线程进行活动记录事务时遇到问题。当该线程运行时向 Rails 应用程序发出多个请求时,将引发异常。
我收到的异常消息是“在关闭的数据库上调用准备”
我的代码大致如下所示:-
Thread.new do
begin
ActiveRecord::Base.connection_pool.with_connection do
# some long running operations including some ActiveRecord operations
end
rescue => e
puts e.message
end
end
异常消息表明数据库已关闭,但连接池中的连接不应该阻止数据库关闭吗?
我有办法解决这个问题吗?
I am facing an issue while making active record transactions from a thread. When multiple requests are being made to the Rails application while this thread is running, an exception is being thrown.
The exception message I am getting is "prepare called on a closed database"
My code roughly looks like this:-
Thread.new do
begin
ActiveRecord::Base.connection_pool.with_connection do
# some long running operations including some ActiveRecord operations
end
rescue => e
puts e.message
end
end
The exception message indicates that the database is closed, but shouldn't my connection from the connection pool prevent the database from being closed?
Is there a way I can resolve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下链接中提到的步骤。
https://github.com/jnicklas/capybara/issues/450
Try the steps mentioned in the below link.
https://github.com/jnicklas/capybara/issues/450