为什么Rake任务增强在我的本地环境和部署到Heroku

为什么Rake任务增强在我的本地环境和部署到Heroku

本文介绍了为什么Rake任务增强在我的本地环境和部署到Heroku Cedar时有所不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 lib / tasks / foo.rake 中找到了这个:

  Rake :: Task增强do 
print>>>>>>>>> hello from precompile
end
Rake :: Task [










$ b $ code>

当我在本地运行 rake资产:预编译时,将打印这两条消息。

当我推送到heroku时,仅打印非摘要消息。但是,根据buildpack , :: Task [任务] .invoke ruby​​_rake_task任务行然后它就像你期望的那样工作。为什么会这样,并且没有找到原因。



由于这两个变量都是在Heroku构建包中设置的,因此您可以创建自定义构建包,而无需同时设置GROUP和ENV设置,尽管我认为这是过度杀毒。在这种情况下,您应该能够将增强为sets:precompile:primary assets:precompile:all 并获得与您期望的意图类似的结果。


I have this in lib/tasks/foo.rake:

Rake::Task["assets:precompile"].enhance do
  print ">>>>>>>> hello from precompile"
end
Rake::Task["assets:precompile:nondigest"].enhance do
  print ">>>>>>>> hello from precompile:nondigest"
end

When I run rake assets:precompile locally, both messages are printed.

When I push to heroku, only the nondigest message is printed. However, according to the buildpack, the push is executing the exact same command as I am locally.

Why does the enhancement to the base assets:precompile case not work on heroku but does work locally?

解决方案

i've been looking into this issue and I found out that the behavior of the assets:precompile depending on if RAILS_ENV and RAILS_GROUPS are both set or not take a look at this locally.

  # This works
  → bundle exec rake assets:precompile RAILS_ENV=production
  >>>>>>>> hello from precompile:nondigest
  >>>>>>>> hello from precompile

  # This works
  → bundle exec rake assets:precompile RAILS_GROUPS=assets
  >>>>>>>> hello from precompile:nondigest
  >>>>>>>> hello from precompile
  →

  # This does not work :'(
  → bundle exec rake assets:precompile RAILS_ENV=production RAILS_GROUPS=assets
  >>>>>>>> hello from precompile:nondigest
  →

The problem comes from https://github.com/rails/rails/blob/3-2-stable/actionpack/lib/sprockets/assets.rake in invoke_or_reboot_rake_task method if you replace the Rake::Task[task].invoke line with ruby_rake_task task then it works like you would expect it to. I've been poking around on exactly why this is, and haven't found the reason.

Since both variables are set in the Heroku build pack, you could create a custom build pack without setting both GROUP and ENV settings, though I think that is overkill. In this scenario you should be able to enhance assets:precompile:primary or assets:precompile:all and achieve an outcome similar to your desired intent.

这篇关于为什么Rake任务增强在我的本地环境和部署到Heroku Cedar时有所不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 19:04