Added flexible eager load configuration for Resque when used in Rails application#1818
Added flexible eager load configuration for Resque when used in Rails application#1818georgiybykov wants to merge 1 commit intoresque:masterfrom
Conversation
6f4d338 to
4f3b12e
Compare
|
@georgiybykov Is there a reason you don't do something like: Pretty sure this would force rails to load before the resque app? |
|
The file # frozen_string_literal: true
require 'resque/tasks'
namespace :resque do
task :setup => :environment
...
endThe code above is not a solution (does not force preload all classes for the application). @iloveitaly As an alternative, do you suggest to override the # frozen_string_literal: true
require 'resque/tasks'
namespace :resque do
task :setup => :environment
task :preload => :setup do
ActiveSupport.run_load_hooks(:before_eager_load, Rails.application)
Rails.application.config.eager_load_namespaces.each(&:eager_load!)
end
endSince Rake tasks ignore the Rails application
Only if you use Rails That is why in this pull request I suggest to add flexible eager load configuration for Resque when used in Rails application without actions to override the code in Rake tasks in order to setup correctly. |
4f3b12e to
a1fbf6b
Compare
|
Hi @iloveitaly! Could you look at this comment as an answer to your question please? |
|
@georgiybykov your explanation makes sense. Tricky problem! I need to set aside some more time to review your PR. Will hopefully get back to you soon. |
|
Hi @iloveitaly! Thank you again! I would be very grateful for your feedback and I hope you get a chance to review the code soon! Please let me know if I can provide anything else in the meantime. |
a1fbf6b to
037bc9d
Compare
c39042f to
5b97aad
Compare
|
I suspect there's a bit of confusion here:
However:
I believe this task should be deleted, though I might be missing something. Let Rails eager load, and let users control this via Rails. I opened #1867 with this proposal. |
5b97aad to
67c8097
Compare
67c8097 to
ca9a356
Compare
|
@fxn Thank you very much for your comment! My opinion and the main points of the current pull request are:
Based on the above, you are correct, however the users with Rails version task :preload => :setup do
ActiveSupport.run_load_hooks(:before_eager_load, Rails.application)
Rails.application.config.eager_load_namespaces.each(&:eager_load!)
endbecause they cannot control this via the Rails configuration. |
|
We faced this issue today using Resque + Wisper. Lots of events were missed on the background jobs. imho this is a prio A issue since it causes a deviation between the production env in the app server (where eager load is set) and the production evn on the background jobs (where it's not eager loading). People expect that both envs match, but they don't and it's hard to figure that out. 3 years without activity on this PR makes me worry. I think the answer is to switch to solid_queue these days. |


Hi!
We faced a problem when upgraded from Resque
1.27.4to> 2.0.0version (using Resque gem as a dependency in Rails 6.0.4 application with Ruby 2.7.5) and lost many important events silently. The eager load for Resque task did not work was the reason.Our production configuration for
eager_loadis set totrue:Changes documentation between versions says the following:
However, the
eager_loadwill never betrue. SinceResquestarts from Rake task, theeager_loadoption configuration is set tofalsepermanently by default starting from this commit at Rails.Only if your Rails application is
6.1.0version or above, you are able to configure eager loading for Rake tasks environment by usingrake_eager_loadoption that was added in this commit to provide the ability to override the defaultfalsevalue for every rake task of the environment.Based on the above, I propose to add flexible configuration for
eager_load:To configure
eager_loadoption usingResqueinterface you are able to add inconfig/initializers/resque.rbthe following:
Or if you would like to configure the
eager_loadoption depends on your Rails application environment, for example: