Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callbacks are cleared if cache_classes if disabled in development #163

Open
Zank94 opened this issue Aug 20, 2019 · 2 comments
Open

Callbacks are cleared if cache_classes if disabled in development #163

Zank94 opened this issue Aug 20, 2019 · 2 comments

Comments

@Zank94
Copy link

Zank94 commented Aug 20, 2019

Hello everyone,

I've just ran into the same problems as the ones mentioned in #155, even after updating to 1.8.1 to fix the eager_load related issue.
To prevent callbacks clearing in development, I have to set config.cache_classes value to true, which isn't very convenient since it involves restarting the server for changes to take effect.

Any help would be much appreciated :)

Thanks

@tansengming
Copy link
Owner

Hi @Zank94 I'm sorry to hear that you're having trouble with this. Would you mind sharing more details about this? These caching issues are really tough to debug and it'll make it a load easier to figure out with an example app.

@spodlecki
Copy link

I was also having trouble keeping the event callbacks from being reset. require is not causing the file to actually be loaded (not sure why... didn't dig in, might be something obvious that I'm missing.)

lib/stripe/engine.rb

    eager_load_classes = -> class_names {
      class_names.each do |constant|
        begin
          constant.to_s.camelize.constantize
        rescue NameError
          require constant
        end
      end
    }

Given this block, I attempted to run both the full paths and the class names.

    # Ruby 2.6.3
    rails (5.2.4.4)
    stripe (5.28.0)
    stripe-rails (2.2.1)
      rails (>= 5.1)
      responders
      stripe (>= 3.15.0)

Works once, after initial requests no callbacks executed

config.stripe.eager_load = Dir[Rails.root.join('app/services/stripe_events/*.rb').to_s]

Works, and reloads as files are changed

config.stripe.eager_load = Dir[Rails.root.join('app/services/stripe_events/*.rb').to_s].map do |file|
  '::StripeEvents::' + File.basename(file.chomp(File.extname(file))).classify
end

note: eager loading in rspec tests work in both formats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants