每当 gem 时,schedule.rb 中的配置文件与 Rails 一起使用?
我的 Rails 应用程序的 /config 文件夹中有一个名为 config.yml 的文件。 我还有一个初始化程序: config/initializers/load_config.rb ,其中包含以下代码:
APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")
我正在使用每当 gem 来设置 cron 作业,并且想使用我的 APP_CONFIG 来调用这样的函数:
#inside schedule.rb
every 2.hours do
runner "MyModel.someMethod('#{APP_CONFIG['some_value']}')"
end
但是每当 gem 没有当我调用如何将配置中的值合并到我的 Schedule.rb 文件中时,似乎无法识别配置文件
whenever --update-crontab mysite
(而不是对值进行硬编码)?
谢谢!
I have a file called config.yml in my /config folder of my rails application.
I also have an initializer: config/initializers/load_config.rb with the following code:
APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")
I am using the Whenever gem to set up a cron job, and would like to use my APP_CONFIG to call a function like so:
#inside schedule.rb
every 2.hours do
runner "MyModel.someMethod('#{APP_CONFIG['some_value']}')"
end
but the Whenever gem doesn't seem to recognize the config file when I call
whenever --update-crontab mysite
How can I incorporate values from my configuration in my schedule.rb file (instead of hard-coding the value)?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑
schedule.rb
文件以在顶部添加require 'yaml'
语句。然后从初始化程序中添加以下行:或者,您可能只需要直接加载
load_config.rb
文件。那么你应该可以走了。Edit your
schedule.rb
file to add arequire 'yaml'
statement to the top. Then add the line from your initializer:Altenatively, you can probably just require the
load_config.rb
file directly. You should be good to go then.