Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.
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
@jonhyman

This comment has been minimized.

Copy link

@jonhyman jonhyman commented Dec 2, 2013

In Ruby 2.0, you can use thread_variable_get/thread_variable_set instead of keeping the hash around yourself.

@khoan

This comment has been minimized.

Copy link

@khoan khoan commented Apr 5, 2014

how do you use this patch in Rails 4 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment