Permalink
Browse files

Compatibility with Mongoid 4.x and Delayed Job 4.x.

  • Loading branch information...
1 parent f7ba389 commit 965da60b679c977602bc0ec242e3167390855d50 @dblock dblock committed Oct 21, 2013
Showing with 62 additions and 10 deletions.
  1. +3 −0 .travis.yml
  2. +10 −0 CHANGELOG.md
  3. +9 −0 Gemfile
  4. +2 −2 delayed_job_mongoid.gemspec
  5. +3 −0 lib/delayed/backend/mongoid.rb
  6. +10 −8 lib/delayed/plugins.rb
  7. +2 −0 spec/helper.rb
  8. +23 −0 spec/plugins_spec.rb
View
@@ -6,3 +6,6 @@ rvm:
- 2.0.0
services:
- mongodb
+env:
+ - MONGOID_VERSION=3
+ - MONGOID_VERSION=4
View
@@ -1,3 +1,13 @@
+Next Release
+============
+* [#38](https://github.com/collectiveidea/delayed_job_mongoid/pull/38): Fix clearing identity map before each job - [@srleo](https://github.com/srleo)
+* [#43](https://github.com/collectiveidea/delayed_job_mongoid/pull/43): Compatibility with Mongoid 4.x and Delayed Job 4.x - [@dblock](https://github.com/dblock)
+
+2.0.0
+=====
+* Added code coverage with SimpleCov - [@sferik](https://github.com/sferik)
+* Added Mongoid 3.0 support - [@sferik](https://github.com/sferik), [@asavartsov](https://github.com/asavartsov)
+
1.0.2 - 2010-01-12
==================
* Fix a potential memory leak inside mongo when reserving jobs on mongo 1.6+
View
@@ -9,3 +9,12 @@ group :test do
end
gemspec
+
+case version = ENV['MONGOID_VERSION'] || '~> 3.1'
+when /4/
+ gem 'mongoid', github: 'mongoid/mongoid'
+when /3/
+ gem 'mongoid', '~> 3.1'
+else
+ gem 'mongoid', version
+end
@@ -1,8 +1,8 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |spec|
- spec.add_dependency 'delayed_job', '~> 3.0'
- spec.add_dependency 'mongoid', '~> 3.0'
+ spec.add_dependency 'delayed_job', ['>= 3.0', '< 5']
+ spec.add_dependency 'mongoid', ['>= 3.0', '< 5']
spec.authors = ["Chris Gaffney", "Brandon Keepers", "Erik Michaels-Ober"]
spec.email = ['chris@collectiveidea.com', 'brandon@opensoul.com', 'sferik@gmail.com']
spec.files = %w(CHANGELOG.md CONTRIBUTING.md LICENSE.md README.md Rakefile delayed_job_mongoid.gemspec)
@@ -63,6 +63,9 @@ def reload(*args)
super
end
end
+ def self.mongoid3?
+ ::Mongoid.const_defined? :Observer # deprecated in Mongoid 4.x
+ end
end
end
end
View
@@ -2,16 +2,18 @@
# clear Mongoid::IdentityMap before each job
#
-module Delayed
- module Plugins
- class ClearIdentityMap < Plugin
- callbacks do |lifecycle|
- lifecycle.before(:invoke_job) do |worker, &block|
- Mongoid::IdentityMap.clear
+if Delayed::Backend::Mongoid.mongoid3?
+ module Delayed
+ module Plugins
+ class ClearIdentityMap < Plugin
+ callbacks do |lifecycle|
+ lifecycle.before(:invoke_job) do |worker, &block|
+ Mongoid::IdentityMap.clear
+ end
end
end
end
end
-end
-Delayed::Worker.plugins << Delayed::Plugins::ClearIdentityMap
+ Delayed::Worker.plugins << Delayed::Plugins::ClearIdentityMap
+end
View
@@ -17,6 +17,8 @@
class Story
include ::Mongoid::Document
+ field :text
+
def tell; text; end
def whatever(n, _); tell*n; end
def self.count; end
View
@@ -0,0 +1,23 @@
+require 'helper'
+
+if Delayed::Backend::Mongoid.mongoid3?
+ describe Delayed::Backend::Mongoid::Job do
+ let(:worker) { Delayed::Worker.new }
+ before do
+ Delayed::Worker.max_priority = nil
+ Delayed::Worker.min_priority = nil
+ Delayed::Worker.default_priority = 99
+ Delayed::Worker.delay_jobs = true
+ SimpleJob.runs = 0
+ described_class.delete_all
+ end
+ after do
+ Delayed::Worker.reset
+ end
+ it "clears mongoid identity map" do
+ Mongoid::IdentityMap.should_receive(:clear).once
+ job = described_class.enqueue SimpleJob.new, priority: 5
+ worker.work_off
+ end
+ end
+end

0 comments on commit 965da60

Please sign in to comment.