Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
-------------
Expand Down
7 changes: 2 additions & 5 deletions lib/kiqstand/middleware.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,7 +18,6 @@ def call(*args)
ensure
if defined?(::Mongoid)
::Mongoid::IdentityMap.clear
::Mongoid.disconnect_sessions
end
end
end
Expand Down
19 changes: 0 additions & 19 deletions spec/kiqstand/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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