Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for Mongoid 3 and 4 + fix after_fork callback #81

Merged
merged 3 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 1 addition & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sudo: false

matrix:
include:
- rvm: 2.5.3
- rvm: 2.6.6
env:
- MONGOID_VERSION=7
- rvm: 2.3.1
Expand All @@ -15,12 +15,6 @@ matrix:
- rvm: 2.3.1
env:
- MONGOID_VERSION=5
- rvm: 2.2
env:
- MONGOID_VERSION=4
- rvm: 2.5.3
env:
- MONGOID_VERSION=3
- rvm: jruby-head
- rvm: rbx-2
- rvm: ruby-head
Expand All @@ -30,10 +24,3 @@ matrix:
- rvm: ruby-head

services: mongodb

addons:
apt:
sources:
- mongodb-3.2-precise
packages:
- mongodb-org-server
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
### 2.3.2 (Next)
### 3.0.1 (Next)

* Your contribution here.

### 3.0.0 (2019/02/26)

* [#81](https://github.com/collectiveidea/delayed_job_mongoid/pull/81): Drop support for Mongoid 3.0 and 4.0 - [johnnyshields](https://github.com/johnnyshields).
* [#81](https://github.com/collectiveidea/delayed_job_mongoid/pull/81): Perform disconnect on after_fork on all Mongoid versions - [johnnyshields](https://github.com/johnnyshields).

### 2.3.1 (2019/02/26)

* [#77](https://github.com/collectiveidea/delayed_job_mongoid/pull/77): Support Mongoid 7.0 - [Startouf](https://github.com/Startouf).
Expand Down
4 changes: 0 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ when /^6/
gem 'mongoid', '~> 6.0'
when /^5/
gem 'mongoid', '~> 5.0'
when /^4/
gem 'mongoid', '~> 4.0'
when /^3/
gem 'mongoid', '~> 3.1'
else
gem 'mongoid', version
end
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

## Requirements

Mongoid 3, 4, 5, 6 or 7.
Mongoid 5 or later.

(For Mongoid 3 and 4, use 2.x version of this gem)

## Installation

Expand All @@ -28,5 +30,4 @@ To generate `script/delayed_job`:

rails generate delayed_job

That's it. Use [delayed_job](http://github.com/collectiveidea/delayed_job) as
normal.
That's it. Use [delayed_job](http://github.com/collectiveidea/delayed_job) as normal.
21 changes: 10 additions & 11 deletions delayed_job_mongoid.gemspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
Gem::Specification.new do |spec|
spec.add_dependency 'delayed_job', ['>= 3.0', '< 5']
spec.add_dependency 'mongoid', ['>= 3.0', '< 8']
spec.add_dependency 'mongoid-compatibility', '>= 0.4.0'
spec.authors = ['Chris Gaffney', 'Brandon Keepers', 'Erik Michaels-Ober']
spec.email = ['[email protected]', '[email protected]', '[email protected]']
spec.files = %w[CHANGELOG.md CONTRIBUTING.md LICENSE.md README.md delayed_job_mongoid.gemspec] + Dir['lib/**/*.rb']
spec.homepage = 'http://github.com/collectiveidea/delayed_job_mongoid'
spec.licenses = ['MIT']
spec.name = 'delayed_job_mongoid'
spec.require_paths = ['lib']
spec.summary = 'Mongoid backend for delayed_job'
spec.version = '2.3.2'
spec.add_dependency 'mongoid', '>= 5.0'
spec.authors = ['Chris Gaffney', 'Brandon Keepers', 'Erik Michaels-Ober']
spec.email = ['[email protected]', '[email protected]', '[email protected]']
spec.files = %w[CHANGELOG.md CONTRIBUTING.md LICENSE.md README.md delayed_job_mongoid.gemspec] + Dir['lib/**/*.rb']
spec.homepage = 'http://github.com/collectiveidea/delayed_job_mongoid'
spec.licenses = ['MIT']
spec.name = 'delayed_job_mongoid'
spec.require_paths = ['lib']
spec.summary = 'Mongoid backend for delayed_job'
spec.version = '3.0.0'
end
25 changes: 6 additions & 19 deletions lib/delayed/backend/mongoid.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'delayed_job'
require 'mongoid'
require 'mongoid/compatibility'

module Delayed
module Backend
Expand Down Expand Up @@ -33,20 +32,11 @@ def self.db_time_now
# Atomically picks and locks one job from the collection.
def self.reserve(worker, max_run_time = Worker.max_run_time)
right_now = db_time_now

criteria = reservation_criteria worker, right_now, max_run_time

if ::Mongoid::Compatibility::Version.mongoid2? || ::Mongoid::Compatibility::Version.mongoid3? || ::Mongoid::Compatibility::Version.mongoid4?
criteria.find_and_modify(
{ '$set' => { locked_at: right_now, locked_by: worker.name } },
new: true
)
else
criteria.find_one_and_update(
{ '$set' => { locked_at: right_now, locked_by: worker.name } },
return_document: :after
)
end
criteria = reservation_criteria(worker, right_now, max_run_time)
criteria.find_one_and_update(
{ '$set' => { locked_at: right_now, locked_by: worker.name } },
return_document: :after
)
end

# Mongo criteria matching all the jobs the worker can reserver
Expand Down Expand Up @@ -84,10 +74,7 @@ def reload(*args)

# Hook method that is called after a new worker is forked
def self.after_fork
if ::Mongoid::Compatibility::Version.mongoid4?
# to avoid `failed with error "unauthorized"` errors in Mongoid 4.0.alpha2
::Mongoid.default_session.disconnect
end
::Mongoid.disconnect_clients
end
end
end
Expand Down
19 changes: 0 additions & 19 deletions lib/delayed/plugins.rb

This file was deleted.

1 change: 0 additions & 1 deletion lib/delayed_job_mongoid.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'delayed/backend/mongoid'
require 'delayed/serialization/mongoid'
require 'delayed_job'
require 'delayed/plugins'
require 'delayed/yaml/yaml_ext'

Delayed::Worker.backend = :mongoid
4 changes: 2 additions & 2 deletions spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
require 'rspec'
require 'delayed_job_mongoid'
require 'delayed/backend/shared_spec'
require 'mongoid/compatibility'

RSpec.configure do |config|
config.expect_with :rspec do |c|
c.syntax = :expect
end

config.before :all do
Mongoid.logger.level = Logger::INFO
Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
Mongo::Logger.logger.level = Logger::INFO
end
end

Expand Down
23 changes: 0 additions & 23 deletions spec/plugins_spec.rb

This file was deleted.