We have to release the current thread's Active Record connection after
performing each job, in case another thread is waiting to use it.
On Rails 4 and earlier, this is handled with middleware. On Rails 5 in
development mode, the reloader does it by delegating to the executor.
However on Rails 5 in production mode, we're not adding the middleware
or enabling the reloader, so connections will never be released.
We can call the executor directly to have it release the connection for
us in this case. By calling it inside the middleware stack, the job will
be retried if the executor raises, avoiding the problem with lost jobs
that led to the reloader being disabled in production.
* Prevent AR middleware and reloader clash
The ActiveRecord middleware releases any current ActiveRecord
connections before the reloader has a chance to clear their query
caches.
We can just remove this middleware because the reloader takes care of
clearing active connections, too.
* Make sure folks haven't added the middleware manually
* Fix the conditional
* Mention that the reloader also clears connections
* Move it all back into a single method
* Typos
* Pull all rails setup into railtie
* Set the middleware even earlier
Also clarify exactly when these hooks are run.
* Only check ActiveRecord reloader/middleware sanity at boot
Checking if the constant is define and including the extensions directly
in the base class will for the class to be loaded. This may cause these
components to be loaded before the time and be missconfigured if the
sidekiq railtie is loaded before the components railtie.
It is unlikely to happen but is better be safe.
Replaced with `__send__` from std lib
* `send` can now be overridden to be more semantically meaningful
* `message.send(user_id)` as opposed to `message.send_message(user_id)`
* `__send__` makes it clear that the reflective version is intended
Workers are the user's classes, the threads are now called processors. Add secret sauce to make Rails config much easier. Use a railtie to auto-add app/workers to the autoload path.