从 Rails 中的线程进行活动记录事务时抛出异常

发布于 2025-01-08 03:05:23 字数 414 浏览 1 评论 0原文

我在从线程进行活动记录事务时遇到问题。当该线程运行时向 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白日梦 2025-01-15 03:05:23

尝试以下链接中提到的步骤。

https://github.com/jnicklas/capybara/issues/450

Try the steps mentioned in the below link.

https://github.com/jnicklas/capybara/issues/450

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文