我有一个 Rails 任务:我应该使用 script/runner 还是 rake?

编程入门 行业动态 更新时间:2024-10-17 20:19:55
本文介绍了我有一个 Rails 任务:我应该使用 script/runner 还是 rake?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

对于ad hoc Rails 任务,我们有几个实现替代方案,其中主要的似乎是:

For ad hoc Rails tasks we have a few implementation alternatives, chief among which would seem to be:

script/runner some_useful_thing

和:

rake some:other_useful_thing

我应该更喜欢哪个选项?如果有一个明显的最爱,那么我什么时候应该考虑使用另一个?如果从来没有,那么您为什么会认为它仍然存在于框架中而没有弃用警告?

Which option should I prefer? If there's a clear favourite then when, if ever, should I consider using the other? If never, then why would you suppose it's still present in the framework without deprecation warnings?

推荐答案

它们之间的区别在于 script/runner 会引导 Rails 而 Rake 任务不会,除非您通过使任务依赖于:environment,像这样:

The difference between them is that script/runner boots Rails whereas a Rake task doesn't unless you tell it to by making the task depend on :environment, like this:

task :some_useful_task => :environment do # do some useful task end

由于启动 Rails 很昂贵,如果可以避免的话,可能值得跳过.

Since booting Rails is expensive, it might be worth skipping if you can avoid it.

除此之外,它们大致相同.我两者都使用,但最近我更多地使用 script/runner 单独执行脚本.

Other than that, they are roughly equivalent. I use both, but lately I've used script/runner executing a script separately more.

更多推荐

我有一个 Rails 任务:我应该使用 script/runner 还是 rake?

本文发布于:2023-11-12 10:41:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581262.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我有一个   Rails   script   runner   rake

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!