[英]issue with establish_connection and rake task together
I have a model and in which i use establish_connection
to connect to different database(let name it remote database
) of other application. 我有一个模型,在其中我使用establish_connection
连接到其他应用程序的不同数据库(将其命名为remote database
)。
example: 例:
class User < ActiveRecord::Base
establish_connection(some_database_credential_hash)
self.class_name = "members"
end
and in production environment i am running a rake task which uses User class
in it.My question is that if the same rake task runs every hour, will it try to make new connection every time to new members table of remote database increasing load and pool on that database? 在生产环境中,我正在运行一个使用User class
的rake任务。我的问题是,如果同一rake任务每小时运行一次,它将每次尝试与远程数据库的新成员表建立新连接,从而增加负载和池在那个数据库上? if Yes, how can i avoid it? 如果是,我如何避免呢? Please suggest. 请提出建议。
This was answered in comments: 这在评论中得到了回答:
This can be confirmed by logging in to (in this case) mysql and running 可以通过登录(在这种情况下)mysql并运行来确认
show processlist 显示过程清单
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.