如题。 程序中使用到了 rufus/scheduler。
代码是这样的:
def run
# db operation
threads << Thread.new(keyword) do |k|
# db operation
end
end
def db(&block)
begin
Connection::Weibowarning.conn
yield
rescue =>ex
raise ex
ensure
ActiveRecord::Base.connection.close
end
end
scheduler.every '60s' do
db { run }
end
然后就会报: DEPRECATION WARNING: Database connections will not be closed automatically, please close your database connection at the end of the thread by calling close on your connection. For example: ActiveRecord::Base.connection.close
我试过在 run 方法中的两个 db operation 前后分别连接和关闭,但是也会提示这个错。
请问该怎么解决呢?