Rails:同时运行多个 rake 任务?
一直喜欢 Rails,但仍然为从命令行运行任务需要多长时间而苦苦挣扎。
我想知道是否可以组合多个 rake 任务,而无需每次都重新加载环境。例如,如果我运行
rails generate rspec:install && rails generate model test_model title:string && rake db:migrate
它将花费 10 秒加载 Rails 来运行 rspec 安装,然后再花费 10 秒加载生成模型的环境,然后再花费 10 秒加载迁移。有没有办法让所有 3 个命令保持相同的环境打开?
Been loving rails, but still struggling with how long it takes to run tasks from the command line.
I'm wondering if it's possible to combine multiple rake tasks without reloading the environment each time. For example, if I run
rails generate rspec:install && rails generate model test_model title:string && rake db:migrate
it will spend 10 seconds loading up rails to run the rspec install, then another ten seconds to load up the environment for generate model, then another for the migration. Is there a way to keep the same environment open for all 3 commands?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下 rails-sh gem - 它会启动 Rails 环境,然后呈现一个命令行界面,因此您可以可以在其中运行您的命令。使用它时有一些限制(我认为您不能更改 RAILS_ENV),但对于您的用例来说,它应该是完美的。
如果你的命令只是 rake 任务,你可以使用空格来分隔它们,例如:
会变成
Take a look at the rails-sh gem - it boots the Rails environment, and then presents a command line interface, so you can run your command within it. There are limitations when using it (I don't think you can change your RAILS_ENV), but for your use-case, it should be perfect.
If your commands are just rake tasks, you can use spaces to separate them, e.g.:
would become