在 Rails 应用程序中存储 Configatron 配置的正确/最佳位置是什么?
我正在将 configatron gem 用于新的 Rails 应用程序,该应用程序由活动记录。我的一些 configatron 设置是在文件中设置的,有些是从数据库中提取的,因为它们会不时更改,这里是我的 configatron.rb 中的几行,
configatron.app.uptime.start = Time.now
configatron.email.signature = Setting.where(:keyname => "email_signature").first.value.to_s unless Setting.where(:keyname => "email_signature").first.nil?
因为这个应用程序从多个邮件程序发送多封电子邮件 - 这是一个将这个全局配置保存在一个地方的好方法,而且它减少了签名的数据库查找。如果由于某种原因站点管理员决定更改它 - 他们可以通过网络管理界面来完成此操作,该界面将更新我的设置表(与设置模型相关)。
这一切都是快乐的&很好,但是存储 configatron.rb 的最佳位置在哪里?现在它位于我的初始化程序文件夹中。这意味着它将在应用程序启动时加载一次 - 这很好,但是如果其中一项设置发生更改 - 站点管理员决定调整电子邮件签名以提及新的促销网站 - 为了使更改生效 - 我需要重新启动应用程序(运行乘客 - 因此从代码中执行 touch tmp/restart.txt
很简单)。然而,这意味着我不想重置的其他配置器设置(例如我的正常运行时间开始时间戳)也将被重置。
那么,移动我的 configatron.rb 并从中加载的更好位置是什么呢? 在启动时加载一次,然后更改一些配置而不重新启动应用程序?
谢谢。
I'm using the configatron gem for a new Rails app that is backed up by ActiveRecord. Some of my configatron settings are set in a file and some are pulled from DB, as they will change from time to time, here are a couple of lines from my configatron.rb
configatron.app.uptime.start = Time.now
configatron.email.signature = Setting.where(:keyname => "email_signature").first.value.to_s unless Setting.where(:keyname => "email_signature").first.nil?
Since this app sends multiple emails from multiple mailers - that is a good way to keep this global config in one place, plus it reduces db lookups for signature. If for some reason site admin decides to change it - they can do it through web admin interface that will update my settings table ( tied to Setting model).
This is all jolly & good, however what is the best place to store configatron.rb? Right now it's sitting in my initializers folder. Which means it will load once on application startup - which is good, however if one of the settings changes - site admin decides to tweak email signature to mention a new promotional website - in order for the change to take effect - I would need to restart app ( running passenger - so it trivial to do touch tmp/restart.txt
from code). However that means other configatron settings that I don't wont to reset ( such as my uptime start timestamp) will be reset as well.
So what is a better place to move my configatron.rb and load from so that it would allow for
loading once on startup and then changing some configs without and app restart?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为将其放入初始化程序中是存储它的正确位置。
如果您想在不重新启动应用程序的情况下更新配置,通常会设置一个“看门狗”。定期提取数据库以检查配置更新的某个进程。您还可以实现某种回调,将更改的配置推送到您的应用程序。
i think that putting it in an initializer is the right place to store it.
if you want to update the configuration without restarting the application, you would normally setup a "watchdog". some process that pulls the database regulary to check for configuration updates. you could also implement some kind of callback that pushes changed configurations to your app.
当我将 configatron 放入初始化程序时,Rails 环境变量会在加载 configatron 设置之前加载。结果,Rails 配置 (config/environments/Production.rb) 中加载的中间件无法使用 configatron 变量。
所以我最终将它作为第一件事加载到environment.rb中
when i put configatron to initializer, Rails environment variables load before loading configatron settings. As effect, middleware loaded in Rails configuration (config/environments/production.rb) was unable to use configatron variables.
so i ended up loading it as first thing in environment.rb instead