Last active
August 31, 2017 12:28
-
-
Save markmeeus/6412088 to your computer and use it in GitHub Desktop.
A patch to reuse Moped connections in Mongoid inside Celluliod Actors. If you use Sidekiq with loads of work, you may want reuse your connections.
Do not use this toghether with kiqstand as they try to achieve opposite results.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Celluloid | |
class Thread < ::Thread | |
def []= key, value | |
if key_on_thread? key | |
thread_vars[key] = value | |
else | |
super | |
end | |
end | |
def [] key | |
if key_on_thread? key | |
thread_vars[key] | |
else | |
super | |
end | |
end | |
private | |
def thread_vars | |
@thread_vars ||= {} | |
end | |
def key_on_thread? key | |
key == "[mongoid]:sessions" | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how do you use this patch in Rails 4 ?