有没有办法知道 Rails 应用程序已从 rake 命令启动?
我正在 Rails 初始化程序中执行大量缓存任务。 它们对网站很有用,但当我启动 rake 任务时绝对无用且耗时。
Rails 有没有办法知道应用程序何时从 rake 命令启动?
谢谢
I'm doing a bunch of caching tasks in my rails initializers.
They're useful for the website, but absolutely useless and time consuming when I launch rake tasks.
Is there a way in rails to know when the app has been launched from a rake command?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想另一个选择是询问您是否可以判断应用程序是否已作为网站启动,然后只运行初始化程序。
在这种情况下,您应该能够在运行应用程序的任何 Web 服务器中设置环境变量,然后您就可以在设置环境变量时触发初始化程序。像这样的东西:
I guess the other option is to ask whether you can tell whether the app has been launched as a website and only run the initializers then.
In that case you should be able to set environment variables in whichever web server you are running the application and you may then be able to trigger your initializer when the environment variable is set. Something like: