'How to prevent ArgumentError (A copy of PaymentFailed has been removed from the > module tree but is still active!) with StripeEvents / Webhooks?

I am using the StripeEvent gem to handle web hooks coming from Stripe.

In my Rails initializer I've got this:

StripeEvent.configure do |events|

  events.subscribe 'invoice.payment_succeeded', PaymentSucceeded.new
  events.subscribe 'invoice.payment_failed', PaymentFailed.new

end

I've also got a folder app/stripe_events where I keep classes like these:

class PaymentFailed

  def call(event)
    StripeMailer.admin_payment_failed(event.data.object).deliver_now
  end

end

The problem is that I keep getting this error every now and then:

ArgumentError (A copy of PaymentFailed has been removed from the module tree but is still active!)

I guess that's because everything inside app is constantly being reloaded by Rails while the StripeEvent.configure bits in the initializer are not?

How can this be prevented?

Thanks for any pointers.



Solution 1:[1]

In my case, I only get this error when I make a change to the event handler or config files. Restarting the server always fixes it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 calyxofheld