From 7f322b34193a8a732edd61bac91b86a2b81edd44 Mon Sep 17 00:00:00 2001 From: Jonathan Hyman Date: Mon, 9 Dec 2013 14:15:00 -0500 Subject: [PATCH] Gets rid of disconnecting sessions as that is going to happen anyway since the session is stored on Fiber-local variables. Adds a note about how to reuse connections. --- README.md | 8 +++++++- lib/kiqstand/middleware.rb | 7 ++----- spec/kiqstand/middleware_spec.rb | 19 ------------------- 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index a84d154..3c32d51 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,13 @@ Kiqstand [![Build Status](https://secure.travis-ci.org/mongoid/kiqstand.png?branch=master&.png)](http://travis-ci.org/mongoid/kiqstand) ======== -Kiqstand is a middleware for Sidekiq for use with Mongoid 3. +Kiqstand is a middleware for Sidekiq for use with Mongoid 3. It will clear the Mongoid::IdentityMap after each job is +processed. + +Note that because Mongoid sessions are stored on Fiber-local variables, they will automatically disconnect after each +job. If you want to re-use connections, see +[this Mongoid user group discussion](https://groups.google.com/forum/#!topic/mongoid/8rpSlgsRSSc) to patch +`Celluloid::Thread`. Compatibility ------------- diff --git a/lib/kiqstand/middleware.rb b/lib/kiqstand/middleware.rb index cd1c03e..233d5d2 100644 --- a/lib/kiqstand/middleware.rb +++ b/lib/kiqstand/middleware.rb @@ -1,13 +1,11 @@ # encoding: utf-8 module Kiqstand - # This is the middleware for ensuring Moped sessions are diconnected after - # a worker runs, and that the identity map is cleared. + # This is the middleware for ensuring the Mongoid identity map is cleared. class Middleware # Ensures that after each worker runs, the identity map is cleared in case - # it was accidentally enabled in this environment, and each session - # disconnects it's nodes. + # it was accidentally enabled in this environment. # # @example Execute the worker. # worker.call @@ -20,7 +18,6 @@ def call(*args) ensure if defined?(::Mongoid) ::Mongoid::IdentityMap.clear - ::Mongoid.disconnect_sessions end end end diff --git a/spec/kiqstand/middleware_spec.rb b/spec/kiqstand/middleware_spec.rb index d9af20e..d221a6f 100644 --- a/spec/kiqstand/middleware_spec.rb +++ b/spec/kiqstand/middleware_spec.rb @@ -24,24 +24,5 @@ class Model end end - context "when a session is alive" do - - before do - Model.create - middleware.call {} - end - - let(:sessions) do - Mongoid::Threaded.sessions.values - end - - it "disconnects the session" do - sessions.each do |session| - session.cluster.nodes.each do |node| - node.send(:connected?).should be_false - end - end - end - end end end