From 89d61938fe5acec288eddcc8be5f5625bc0b18b7 Mon Sep 17 00:00:00 2001 From: Moncef Belyamani Date: Sat, 23 Sep 2017 22:06:06 -0400 Subject: [PATCH] Move WorkerHealthChecker from app/services to lib **Why**: Middleware, such as `WorkerHealthChecker::Middleware` can't be reloaded, but because the `WorkerHealthChecker` module was placed in `app/services`, it automatically gets reloaded by Rails, which results in the following error when running Sidekiq jobs while Rails is trying to clean up and unload code: ``` ArgumentError: A copy of WorkerHealthChecker::Middleware has been removed from the module tree but is still active! ``` The solution is to move the module to a path that is not included in the Rails autoload paths, such as `lib`. A negative side effect of this issue is that any background job that ran before Rails raised the error (when it was trying to clean up and unload the code), will keep running over and over because Sidekiq automatically retries failed jobs. I experienced this locally by getting the same email over and over, and I'm assuming this is the same issue that caused some of our production users to keep getting the same SMS over and over. Jenny also saw this in INT in June. --- config/initializers/sidekiq.rb | 1 + {app/services => lib}/worker_health_checker.rb | 0 spec/{services => lib}/worker_health_checker_spec.rb | 0 3 files changed, 1 insertion(+) rename {app/services => lib}/worker_health_checker.rb (100%) rename spec/{services => lib}/worker_health_checker_spec.rb (100%) diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 9f66213acd5..fc8681bb8fc 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -1,5 +1,6 @@ require 'encrypted_sidekiq_redis' require 'sidekiq_logger_formatter' +require 'worker_health_checker' Sidekiq::Logging.logger.level = Logger::WARN Sidekiq::Logging.logger.formatter = SidekiqLoggerFormatter.new diff --git a/app/services/worker_health_checker.rb b/lib/worker_health_checker.rb similarity index 100% rename from app/services/worker_health_checker.rb rename to lib/worker_health_checker.rb diff --git a/spec/services/worker_health_checker_spec.rb b/spec/lib/worker_health_checker_spec.rb similarity index 100% rename from spec/services/worker_health_checker_spec.rb rename to spec/lib/worker_health_checker_spec.rb