Permalink
Browse files

Remove MongoMapper backend

MongoMapper is not compatible with Rails 3 yet. When it is, someone can resurrect this code in a separate gem like the other backends.
  • Loading branch information...
1 parent c7d16ab commit 1815f283632db670a8de0184804ef1d1cb61a6d8 @bkeepers bkeepers committed Sep 5, 2010
View
@@ -51,17 +51,6 @@ $ script/generate delayed_job
$ rake db:migrate
</pre>
-h3. MongoMapper
-
-You must use @MongoMapper.setup@ in the initializer:
-
-<pre>
-config = YAML::load(File.read(Rails.root.join('config/mongo.yml')))
-MongoMapper.setup(config, Rails.env)
-
-Delayed::Worker.backend = :mongo_mapper
-</pre>
-
h3. DataMapper
<pre>
View
@@ -24,7 +24,6 @@ Jeweler::Tasks.new do |s|
s.add_development_dependency "rspec"
s.add_development_dependency "sqlite3-ruby"
s.add_development_dependency "activerecord"
- s.add_development_dependency "mongo_mapper"
s.add_development_dependency "dm-core"
s.add_development_dependency "dm-observer"
s.add_development_dependency "dm-aggregates"
View
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Brandon Keepers", "Tobias L\303\274tke"]
- s.date = %q{2010-05-21}
+ s.date = %q{2010-09-04}
s.description = %q{Delayed_job (or DJ) encapsulates the common pattern of asynchronously executing longer tasks in the background. It is a direct extraction from Shopify where the job table is responsible for a multitude of core tasks.
This gem is collectiveidea's fork (http://github.com/collectiveidea/delayed_job).}
@@ -35,7 +35,7 @@ This gem is collectiveidea's fork (http://github.com/collectiveidea/delayed_job)
"lib/delayed/backend/base.rb",
"lib/delayed/backend/couch_rest.rb",
"lib/delayed/backend/data_mapper.rb",
- "lib/delayed/backend/mongo_mapper.rb",
+ "lib/delayed/backend/shared_spec.rb",
"lib/delayed/command.rb",
"lib/delayed/message_sending.rb",
"lib/delayed/performable_method.rb",
@@ -55,17 +55,15 @@ This gem is collectiveidea's fork (http://github.com/collectiveidea/delayed_job)
"spec/backend/active_record_job_spec.rb",
"spec/backend/couch_rest_job_spec.rb",
"spec/backend/data_mapper_job_spec.rb",
- "spec/backend/mongo_mapper_job_spec.rb",
- "spec/backend/shared_backend_spec.rb",
"spec/message_sending_spec.rb",
"spec/performable_method_spec.rb",
"spec/sample_jobs.rb",
"spec/setup/active_record.rb",
"spec/setup/couch_rest.rb",
"spec/setup/data_mapper.rb",
- "spec/setup/mongo_mapper.rb",
"spec/spec_helper.rb",
"spec/worker_spec.rb",
+ "spec/yaml_ext_spec.rb",
"tasks/jobs.rake"
]
s.homepage = %q{http://github.com/collectiveidea/delayed_job}
@@ -76,7 +74,8 @@ This gem is collectiveidea's fork (http://github.com/collectiveidea/delayed_job)
s.test_files = [
"spec/message_sending_spec.rb",
"spec/performable_method_spec.rb",
- "spec/worker_spec.rb"
+ "spec/worker_spec.rb",
+ "spec/yaml_ext_spec.rb"
]
if s.respond_to? :specification_version then
@@ -88,7 +87,6 @@ This gem is collectiveidea's fork (http://github.com/collectiveidea/delayed_job)
s.add_development_dependency(%q<rspec>, [">= 0"])
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
s.add_development_dependency(%q<activerecord>, [">= 0"])
- s.add_development_dependency(%q<mongo_mapper>, [">= 0"])
s.add_development_dependency(%q<dm-core>, [">= 0"])
s.add_development_dependency(%q<dm-observer>, [">= 0"])
s.add_development_dependency(%q<dm-aggregates>, [">= 0"])
@@ -100,7 +98,6 @@ This gem is collectiveidea's fork (http://github.com/collectiveidea/delayed_job)
s.add_dependency(%q<rspec>, [">= 0"])
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
s.add_dependency(%q<activerecord>, [">= 0"])
- s.add_dependency(%q<mongo_mapper>, [">= 0"])
s.add_dependency(%q<dm-core>, [">= 0"])
s.add_dependency(%q<dm-observer>, [">= 0"])
s.add_dependency(%q<dm-aggregates>, [">= 0"])
@@ -113,7 +110,6 @@ This gem is collectiveidea's fork (http://github.com/collectiveidea/delayed_job)
s.add_dependency(%q<rspec>, [">= 0"])
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
s.add_dependency(%q<activerecord>, [">= 0"])
- s.add_dependency(%q<mongo_mapper>, [">= 0"])
s.add_dependency(%q<dm-core>, [">= 0"])
s.add_dependency(%q<dm-observer>, [">= 0"])
s.add_dependency(%q<dm-aggregates>, [">= 0"])
@@ -1,106 +0,0 @@
-require 'mongo_mapper'
-
-MongoMapper::Document.class_eval do
- yaml_as "tag:ruby.yaml.org,2002:MongoMapper"
-
- def self.yaml_new(klass, tag, val)
- klass.find(val['_id'])
- end
-
- def to_yaml_properties
- ['@_id']
- end
-end
-
-module Delayed
- module Backend
- module MongoMapper
- class Job
- include ::MongoMapper::Document
- include Delayed::Backend::Base
- set_collection_name 'delayed_jobs'
-
- key :priority, Integer, :default => 0
- key :attempts, Integer, :default => 0
- key :handler, String
- key :run_at, Time
- key :locked_at, Time
- key :locked_by, String, :index => true
- key :failed_at, Time
- key :last_error, String
- timestamps!
-
- before_save :set_default_run_at
-
- ensure_index [[:priority, 1], [:run_at, 1]]
-
- def self.before_fork
- ::MongoMapper.connection.close
- end
-
- def self.after_fork
- ::MongoMapper.connect(RAILS_ENV)
- end
-
- def self.db_time_now
- Time.now.utc
- end
-
- def self.find_available(worker_name, limit = 5, max_run_time = Worker.max_run_time)
- right_now = db_time_now
-
- conditions = {
- :run_at => {"$lte" => right_now},
- :limit => -limit, # In mongo, positive limits are 'soft' and negative are 'hard'
- :failed_at => nil,
- :sort => [['priority', 1], ['run_at', 1]]
- }
-
- where = "this.locked_at == null || this.locked_at < #{make_date(right_now - max_run_time)}"
-
- (conditions[:priority] ||= {})['$gte'] = Worker.min_priority.to_i if Worker.min_priority
- (conditions[:priority] ||= {})['$lte'] = Worker.max_priority.to_i if Worker.max_priority
-
- results = all(conditions.merge(:locked_by => worker_name))
- results += all(conditions.merge('$where' => where)) if results.size < limit
- results
- end
-
- # When a worker is exiting, make sure we don't have any locked jobs.
- def self.clear_locks!(worker_name)
- collection.update({:locked_by => worker_name}, {"$set" => {:locked_at => nil, :locked_by => nil}}, :multi => true)
- end
-
- # Lock this job for this worker.
- # Returns true if we have the lock, false otherwise.
- def lock_exclusively!(max_run_time, worker = worker_name)
- right_now = self.class.db_time_now
- overtime = right_now - max_run_time.to_i
-
- query = "this.locked_at == null || this.locked_at < #{make_date(overtime)} || this.locked_by == #{worker.to_json}"
- conditions = {:_id => id, :run_at => {"$lte" => right_now}, "$where" => query}
-
- collection.update(conditions, {"$set" => {:locked_at => right_now, :locked_by => worker}})
- affected_rows = collection.find({:_id => id, :locked_by => worker}).count
- if affected_rows == 1
- self.locked_at = right_now
- self.locked_by = worker
- return true
- else
- return false
- end
- end
-
- private
-
- def self.make_date(date_or_seconds)
- "new Date(#{date_or_seconds.to_f * 1000})"
- end
-
- def make_date(date)
- self.class.make_date(date)
- end
- end
- end
- end
-end
View
@@ -37,14 +37,7 @@ def self.backend=(backend)
end
def self.guess_backend
- self.backend ||= if defined?(ActiveRecord)
- :active_record
- elsif defined?(MongoMapper)
- :mongo_mapper
- else
- logger.warn "Could not decide on a backend, defaulting to active_record"
- :active_record
- end
+ self.backend = :active_record if defined?(ActiveRecord)
end
def initialize(options={})
@@ -1,94 +0,0 @@
-require 'spec_helper'
-require 'backend/shared_backend_spec'
-require 'delayed/backend/mongo_mapper'
-
-describe Delayed::Backend::MongoMapper::Job do
- before(:all) do
- @backend = Delayed::Backend::MongoMapper::Job
- end
-
- before(:each) do
- MongoMapper.database.collections.each(&:remove)
- end
-
- it_should_behave_like 'a backend'
-
- describe "indexes" do
- it "should have combo index on priority and run_at" do
- @backend.collection.index_information.detect { |index| index[0] == 'priority_1_run_at_1' }.should_not be_nil
- end
-
- it "should have index on locked_by" do
- @backend.collection.index_information.detect { |index| index[0] == 'locked_by_1' }.should_not be_nil
- end
- end
-
- describe "delayed method" do
- class MongoStoryReader
- def read(story)
- "Epilog: #{story.tell}"
- end
- end
-
- class MongoStory
- include ::MongoMapper::Document
- key :text, String
-
- def tell
- text
- end
- end
-
- it "should ignore not found errors because they are permanent" do
- story = MongoStory.create :text => 'Once upon a time...'
- job = story.delay.tell
- story.destroy
- lambda { job.invoke_job }.should_not raise_error
- end
-
- it "should store the object as string" do
- story = MongoStory.create :text => 'Once upon a time...'
- job = story.delay.tell
-
- job.payload_object.class.should == Delayed::PerformableMethod
- job.payload_object.object.should == story
- job.payload_object.method.should == :tell
- job.payload_object.args.should == []
- job.payload_object.perform.should == 'Once upon a time...'
- end
-
- it "should store arguments as string" do
- story = MongoStory.create :text => 'Once upon a time...'
- job = MongoStoryReader.new.delay.read(story)
- job.payload_object.class.should == Delayed::PerformableMethod
- job.payload_object.method.should == :read
- job.payload_object.args.should == [story]
- job.payload_object.perform.should == 'Epilog: Once upon a time...'
- end
- end
-
- describe "before_fork" do
- after do
- MongoMapper.connection.connect_to_master
- end
-
- it "should disconnect" do
- lambda do
- Delayed::Backend::MongoMapper::Job.before_fork
- end.should change { !!MongoMapper.connection.connected? }.from(true).to(false)
- end
- end
-
- describe "after_fork" do
- before do
- MongoMapper.connection.close
- end
-
- it "should call reconnect" do
- lambda do
- Delayed::Backend::MongoMapper::Job.after_fork
- end.should change { !!MongoMapper.connection.connected? }.from(false).to(true)
- end
- end
-
-end
View
@@ -1,17 +0,0 @@
-require 'mongo_mapper'
-
-MongoMapper.config = {
- RAILS_ENV => {'database' => 'delayed_job'}
-}
-MongoMapper.connect RAILS_ENV
-
-unless defined?(Story)
- class Story
- include ::MongoMapper::Document
- def tell; text; end
- def whatever(n, _); tell*n; end
- def self.count; end
-
- handle_asynchronously :whatever
- end
-end

0 comments on commit 1815f28

Please sign in to comment.