delayed_job_mongoid 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 824ab3dc83ed1613e9e2ece9ed703a411aba94d3
4
+ data.tar.gz: 6a286aae4db6c1efbce2fe0449f88fc652ef6f03
5
+ SHA512:
6
+ metadata.gz: 8134c2be8e5a26297c7c1713791357ce47bbf3d510362748f6726e122addd90dda2f5619c842dca2c66e7100a4879f0c0924ea0eb9af3796d0905f605df57b65
7
+ data.tar.gz: 68ef96228c0e632607e623208d0be3b4cbcc090e9107b080ee1a635ef62dc21f38d8b3604ce705db0efdf2278bc22cc5973e3d4113a385102a216883d1a59912
@@ -0,0 +1,19 @@
1
+ Next Release
2
+ ============
3
+ * [#38](https://github.com/collectiveidea/delayed_job_mongoid/pull/38): Fix clearing identity map before each job - [@srleo](https://github.com/srleo)
4
+ * [#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)
5
+
6
+ 2.0.0
7
+ =====
8
+ * Added code coverage with SimpleCov - [@sferik](https://github.com/sferik)
9
+ * Added Mongoid 3.0 support - [@sferik](https://github.com/sferik), [@asavartsov](https://github.com/asavartsov)
10
+
11
+ 1.0.2 - 2010-01-12
12
+ ==================
13
+ * Fix a potential memory leak inside mongo when reserving jobs on mongo 1.6+
14
+ * Fixed gemspec to work with Mongoid 2.0 RC and Rubygems 1.4
15
+
16
+ 1.0.1 - 2010-12-01
17
+ ==================
18
+ * Use MongoDB's findAndModify to reserve the next available job in one atomic operation
19
+ * Better index
@@ -0,0 +1,14 @@
1
+ ## How to contribute
2
+
3
+ If you find what looks like a bug:
4
+
5
+ * Search the [mailing list](http://groups.google.com/group/delayed_job) to see if anyone else had the same issue.
6
+ * Check the [GitHub issue tracker](http://github.com/collectiveidea/delayed_job_mongoid/issues/) to see if anyone else has reported issue.
7
+ * If you don't see anything, create an issue with information on how to reproduce it.
8
+
9
+ If you want to contribute an enhancement or a fix:
10
+
11
+ * Fork the project on github.
12
+ * Make your changes with tests.
13
+ * Commit the changes without making changes to the Rakefile or any other files that aren't related to your enhancement or fix
14
+ * Send a pull request.
File without changes
data/README.md CHANGED
@@ -1,13 +1,21 @@
1
- # delayed_job Mongoid backend [![Build Status](https://secure.travis-ci.org/collectiveidea/delayed_job_mongoid.png?branch=master)][travis] [![Dependency Status](https://gemnasium.com/collectiveidea/delayed_job_mongoid.png?travis)][gemnasium] [![Code Climate](https://codeclimate.com/badge.png)][codeclimate]
1
+ # DelayedJob Mongoid backend
2
2
 
3
+ [![Gem Version](http://img.shields.io/gem/v/delayed_job_mongoid.svg)][gem]
4
+ [![Build Status](http://img.shields.io/travis/collectiveidea/delayed_job_mongoid.svg)][travis]
5
+ [![Dependency Status](http://img.shields.io/gemnasium/collectiveidea/delayed_job_mongoid.svg)][gemnasium]
6
+ [![Code Climate](http://img.shields.io/codeclimate/github/collectiveidea/delayed_job_mongoid.svg)][codeclimate]
7
+ [![Coverage Status](http://img.shields.io/coveralls/collectiveidea/delayed_job_mongoid.svg)][coveralls]
8
+
9
+ [gem]: https://rubygems.org/gems/delayed_job_mongoid
3
10
  [travis]: http://travis-ci.org/collectiveidea/delayed_job_mongoid
4
11
  [gemnasium]: https://gemnasium.com/collectiveidea/delayed_job_mongoid
5
12
  [codeclimate]: https://codeclimate.com/github/collectiveidea/delayed_job_mongoid
13
+ [coveralls]: https://coveralls.io/r/collectiveidea/delayed_job_mongoid
6
14
 
7
15
  ## Requirements
8
16
 
9
- Make sure you are using MongoDB version 1.3 or newer. `delayed_job_mongoid` uses the `findandmodify` command which is only available in recent versions.
10
-
17
+ Make sure you are using MongoDB version 1.3 or newer. `delayed_job_mongoid`
18
+ uses the `findandmodify` command which is only available in recent versions.
11
19
 
12
20
  ## Installation
13
21
 
@@ -15,8 +23,14 @@ Add the gem to your Gemfile:
15
23
 
16
24
  gem 'delayed_job_mongoid'
17
25
 
18
- After running `bundle install`, create the indexes (and don't forget to do this on your production database):
26
+ After running `bundle install`, create the indexes (and don't forget to do this
27
+ on your production database):
19
28
 
20
29
  script/rails runner 'Delayed::Backend::Mongoid::Job.create_indexes'
21
30
 
22
- That's it. Use [delayed_job as normal](http://github.com/collectiveidea/delayed_job).
31
+ To generate script/delayed_job:
32
+
33
+ rails generate delayed_job
34
+
35
+ That's it. Use [delayed_job](http://github.com/collectiveidea/delayed_job) as
36
+ normal.
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rspec/core/rake_task'
7
+ desc 'Run the specs'
8
+ RSpec::Core::RakeTask.new do |r|
9
+ r.verbose = false
10
+ end
11
+
12
+ task :test => :spec
13
+
14
+ begin
15
+ require 'rubocop/rake_task'
16
+ Rubocop::RakeTask.new
17
+ rescue LoadError
18
+ task :rubocop do
19
+ $stderr.puts 'Rubocop is disabled'
20
+ end
21
+ end
22
+
23
+ require 'yardstick/rake/measurement'
24
+ Yardstick::Rake::Measurement.new do |measurement|
25
+ measurement.output = 'measurement/report.txt'
26
+ end
27
+
28
+ require 'yardstick/rake/verify'
29
+ Yardstick::Rake::Verify.new do |verify|
30
+ verify.require_exact_threshold = false
31
+ verify.threshold = 53.3
32
+ end
33
+
34
+ task :default => [:spec, :rubocop, :verify_measurements]
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.add_dependency 'delayed_job', ['>= 3.0', '< 5']
5
+ spec.add_dependency 'mongoid', ['>= 3.0', '< 5']
6
+ spec.authors = ['Chris Gaffney', 'Brandon Keepers', 'Erik Michaels-Ober']
7
+ spec.email = ['chris@collectiveidea.com', 'brandon@opensoul.com', 'sferik@gmail.com']
8
+ spec.files = %w[CHANGELOG.md CONTRIBUTING.md LICENSE.md README.md Rakefile delayed_job_mongoid.gemspec]
9
+ spec.files += Dir.glob('lib/**/*.rb')
10
+ spec.files += Dir.glob('spec/**/*')
11
+ spec.homepage = 'http://github.com/collectiveidea/delayed_job_mongoid'
12
+ spec.licenses = ['MIT']
13
+ spec.name = 'delayed_job_mongoid'
14
+ spec.require_paths = ['lib']
15
+ spec.summary = 'Mongoid backend for delayed_job'
16
+ spec.test_files = Dir.glob('spec/**/*')
17
+ spec.version = '2.1.0'
18
+ end
@@ -35,13 +35,13 @@ module Delayed
35
35
  def self.reserve(worker, max_run_time = Worker.max_run_time)
36
36
  right_now = db_time_now
37
37
 
38
- criteria = self.where(
39
- :run_at => {"$lte" => right_now},
38
+ criteria = where(
39
+ :run_at => {'$lte' => right_now},
40
40
  :failed_at => nil
41
41
  ).any_of(
42
- { :locked_by => worker.name },
43
- { :locked_at => nil },
44
- { :locked_at => { '$lt' => (right_now - max_run_time) }}
42
+ {:locked_by => worker.name},
43
+ {:locked_at => nil},
44
+ {:locked_at => {'$lt' => (right_now - max_run_time)}}
45
45
  )
46
46
 
47
47
  criteria = criteria.gte(:priority => Worker.min_priority.to_i) if Worker.min_priority
@@ -49,19 +49,28 @@ module Delayed
49
49
  criteria = criteria.any_in(:queue => Worker.queues) if Worker.queues.any?
50
50
 
51
51
  criteria.desc(:locked_by).asc(:priority).asc(:run_at).find_and_modify(
52
- {"$set" => {:locked_at => right_now, :locked_by => worker.name}}, :new => true
52
+ {'$set' => {:locked_at => right_now, :locked_by => worker.name}}, :new => true
53
53
  )
54
54
  end
55
55
 
56
56
  # When a worker is exiting, make sure we don't have any locked jobs.
57
57
  def self.clear_locks!(worker_name)
58
- self.where(:locked_by => worker_name).update_all({:locked_at => nil, :locked_by => nil})
58
+ where(:locked_by => worker_name).update_all(:locked_at => nil, :locked_by => nil)
59
59
  end
60
60
 
61
61
  def reload(*args)
62
62
  reset
63
63
  super
64
64
  end
65
+
66
+ # Hook method that is called after a new worker is forked
67
+ def self.after_fork
68
+ # to avoid `failed with error "unauthorized"` errors in Mongoid 4.0.alpha2
69
+ ::Mongoid.default_session.disconnect
70
+ end
71
+ end
72
+ def self.mongoid3?
73
+ ::Mongoid.const_defined? :Observer # deprecated in Mongoid 4.x
65
74
  end
66
75
  end
67
76
  end
@@ -0,0 +1,19 @@
1
+ #
2
+ # clear Mongoid::IdentityMap before each job
3
+ #
4
+
5
+ if Delayed::Backend::Mongoid.mongoid3?
6
+ module Delayed
7
+ module Plugins
8
+ class ClearIdentityMap < Plugin
9
+ callbacks do |lifecycle|
10
+ lifecycle.before(:invoke_job) do
11
+ Mongoid::IdentityMap.clear
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ Delayed::Worker.plugins << Delayed::Plugins::ClearIdentityMap
19
+ end
@@ -4,14 +4,12 @@ require 'mongoid'
4
4
 
5
5
  if YAML.parser.class.name =~ /syck/i
6
6
  Mongoid::Document.class_eval do
7
- yaml_as "tag:ruby.yaml.org,2002:Mongoid"
7
+ yaml_as 'tag:ruby.yaml.org,2002:Mongoid'
8
8
 
9
- def self.yaml_new(klass, tag, val)
10
- begin
11
- klass.find(val['attributes']['_id'])
12
- rescue Mongoid::Errors::DocumentNotFound
13
- raise Delayed::DeserializationError
14
- end
9
+ def self.yaml_new(klass, _, val)
10
+ klass.find(val['attributes']['_id'])
11
+ rescue Mongoid::Errors::DocumentNotFound
12
+ raise Delayed::DeserializationError
15
13
  end
16
14
 
17
15
  def to_yaml_properties
@@ -21,7 +19,7 @@ if YAML.parser.class.name =~ /syck/i
21
19
  else
22
20
  Mongoid::Document.class_eval do
23
21
  def encode_with(coder)
24
- coder["attributes"] = @attributes
22
+ coder['attributes'] = @attributes
25
23
  coder.tag = ['!ruby/Mongoid', self.class.name].join(':')
26
24
  end
27
25
  end
@@ -2,5 +2,6 @@
2
2
  require 'delayed/backend/mongoid'
3
3
  require 'delayed/serialization/mongoid'
4
4
  require 'delayed_job'
5
+ require 'delayed/plugins'
5
6
 
6
7
  Delayed::Worker.backend = :mongoid
@@ -1,5 +1,5 @@
1
- require 'spec_helper'
1
+ require 'helper'
2
2
 
3
3
  describe Delayed::Backend::Mongoid::Job do
4
- it_should_behave_like 'a delayed_job backend'
4
+ it_behaves_like 'a delayed_job backend'
5
5
  end
@@ -0,0 +1,42 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+
9
+ SimpleCov.start do
10
+ add_filter '/spec/'
11
+ minimum_coverage(77.27)
12
+ end
13
+
14
+ require 'rspec'
15
+ require 'delayed_job_mongoid'
16
+ require 'delayed/backend/shared_spec'
17
+
18
+ RSpec.configure do |config|
19
+ config.expect_with :rspec do |c|
20
+ c.syntax = :expect
21
+ end
22
+ end
23
+
24
+ Mongoid.configure do |config|
25
+ config.connect_to('dl_spec')
26
+ end
27
+
28
+ class Story
29
+ include ::Mongoid::Document
30
+ field :text
31
+
32
+ def tell
33
+ text
34
+ end
35
+
36
+ def whatever(n, _)
37
+ tell * n
38
+ end
39
+ def self.count; end
40
+
41
+ handle_asynchronously :whatever
42
+ end
@@ -0,0 +1,23 @@
1
+ require 'helper'
2
+
3
+ if Delayed::Backend::Mongoid.mongoid3?
4
+ describe Delayed::Backend::Mongoid::Job do
5
+ let(:worker) { Delayed::Worker.new }
6
+ before do
7
+ Delayed::Worker.max_priority = nil
8
+ Delayed::Worker.min_priority = nil
9
+ Delayed::Worker.default_priority = 99
10
+ Delayed::Worker.delay_jobs = true
11
+ SimpleJob.runs = 0
12
+ described_class.delete_all
13
+ end
14
+ after do
15
+ Delayed::Worker.reset
16
+ end
17
+ it 'clears mongoid identity map' do
18
+ expect(Mongoid::IdentityMap).to receive(:clear).once
19
+ described_class.enqueue SimpleJob.new, :priority => 5
20
+ worker.work_off
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,145 +1,105 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_job_mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
5
- prerelease:
4
+ version: 2.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Chris Gaffney
9
8
  - Brandon Keepers
9
+ - Erik Michaels-Ober
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-02 00:00:00.000000000 Z
13
+ date: 2014-05-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: mongoid
16
+ name: delayed_job
17
17
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
18
  requirements:
20
- - - ~>
19
+ - - ">="
21
20
  - !ruby/object:Gem::Version
22
21
  version: '3.0'
22
+ - - "<"
23
+ - !ruby/object:Gem::Version
24
+ version: '5'
23
25
  type: :runtime
24
26
  prerelease: false
25
27
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
28
  requirements:
28
- - - ~>
29
+ - - ">="
29
30
  - !ruby/object:Gem::Version
30
31
  version: '3.0'
32
+ - - "<"
33
+ - !ruby/object:Gem::Version
34
+ version: '5'
31
35
  - !ruby/object:Gem::Dependency
32
- name: delayed_job
36
+ name: mongoid
33
37
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
38
  requirements:
36
- - - ~>
39
+ - - ">="
37
40
  - !ruby/object:Gem::Version
38
41
  version: '3.0'
42
+ - - "<"
43
+ - !ruby/object:Gem::Version
44
+ version: '5'
39
45
  type: :runtime
40
46
  prerelease: false
41
47
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
48
  requirements:
44
- - - ~>
49
+ - - ">="
45
50
  - !ruby/object:Gem::Version
46
51
  version: '3.0'
47
- - !ruby/object:Gem::Dependency
48
- name: rspec
49
- requirement: !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '2.0'
55
- type: :development
56
- prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ! '>='
52
+ - - "<"
61
53
  - !ruby/object:Gem::Version
62
- version: '2.0'
63
- - !ruby/object:Gem::Dependency
64
- name: rake
65
- requirement: !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
68
- - - ! '>='
69
- - !ruby/object:Gem::Version
70
- version: '0.9'
71
- type: :development
72
- prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ! '>='
77
- - !ruby/object:Gem::Version
78
- version: '0.9'
79
- - !ruby/object:Gem::Dependency
80
- name: simplecov
81
- requirement: !ruby/object:Gem::Requirement
82
- none: false
83
- requirements:
84
- - - ! '>='
85
- - !ruby/object:Gem::Version
86
- version: '0.6'
87
- type: :development
88
- prerelease: false
89
- version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
- requirements:
92
- - - ! '>='
93
- - !ruby/object:Gem::Version
94
- version: '0.6'
54
+ version: '5'
95
55
  description:
96
56
  email:
97
57
  - chris@collectiveidea.com
98
58
  - brandon@opensoul.com
59
+ - sferik@gmail.com
99
60
  executables: []
100
61
  extensions: []
101
- extra_rdoc_files:
102
- - LICENSE
103
- - README.md
62
+ extra_rdoc_files: []
104
63
  files:
64
+ - CHANGELOG.md
65
+ - CONTRIBUTING.md
66
+ - LICENSE.md
67
+ - README.md
68
+ - Rakefile
69
+ - delayed_job_mongoid.gemspec
105
70
  - lib/delayed/backend/mongoid.rb
71
+ - lib/delayed/plugins.rb
106
72
  - lib/delayed/serialization/mongoid.rb
107
73
  - lib/delayed_job_mongoid.rb
108
74
  - spec/delayed_job_mongoid_spec.rb
109
- - spec/spec_helper.rb
110
- - LICENSE
111
- - README.md
75
+ - spec/helper.rb
76
+ - spec/plugins_spec.rb
112
77
  homepage: http://github.com/collectiveidea/delayed_job_mongoid
113
- licenses: []
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
114
81
  post_install_message:
115
- rdoc_options:
116
- - --charset=UTF-8
82
+ rdoc_options: []
117
83
  require_paths:
118
84
  - lib
119
85
  required_ruby_version: !ruby/object:Gem::Requirement
120
- none: false
121
86
  requirements:
122
- - - ! '>='
87
+ - - ">="
123
88
  - !ruby/object:Gem::Version
124
89
  version: '0'
125
- segments:
126
- - 0
127
- hash: -913743688657912921
128
90
  required_rubygems_version: !ruby/object:Gem::Requirement
129
- none: false
130
91
  requirements:
131
- - - ! '>='
92
+ - - ">="
132
93
  - !ruby/object:Gem::Version
133
94
  version: '0'
134
- segments:
135
- - 0
136
- hash: -913743688657912921
137
95
  requirements: []
138
96
  rubyforge_project:
139
- rubygems_version: 1.8.23
97
+ rubygems_version: 2.2.2
140
98
  signing_key:
141
- specification_version: 3
99
+ specification_version: 4
142
100
  summary: Mongoid backend for delayed_job
143
101
  test_files:
144
102
  - spec/delayed_job_mongoid_spec.rb
145
- - spec/spec_helper.rb
103
+ - spec/helper.rb
104
+ - spec/plugins_spec.rb
105
+ has_rdoc:
@@ -1,23 +0,0 @@
1
- unless ENV['CI']
2
- require 'simplecov'
3
- SimpleCov.start do
4
- add_filter 'spec'
5
- end
6
- end
7
-
8
- require 'rspec'
9
- require 'delayed_job_mongoid'
10
- require 'delayed/backend/shared_spec'
11
-
12
- Mongoid.configure do |config|
13
- config.connect_to("dl_spec")
14
- end
15
-
16
- class Story
17
- include ::Mongoid::Document
18
- def tell; text; end
19
- def whatever(n, _); tell*n; end
20
- def self.count; end
21
-
22
- handle_asynchronously :whatever
23
- end