Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding very important indexes. Can't believe I forgot them

  • Loading branch information...
commit 770373afaf15c65c95e330c839ac00b3eb23e918 1 parent 80c2ee7
@zbelzer zbelzer authored
View
6 lib/delayed/backend/mongo_mapper.rb
@@ -29,12 +29,14 @@ class Job
key :handler, String
key :run_at, Time
key :locked_at, Time
- key :locked_by, String
+ 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.db_time_now
::MongoMapper.time_class.now.utc
@@ -45,7 +47,7 @@ def self.find_available(worker_name, limit = 5, max_run_time = Worker.max_run_ti
conditions = {
:run_at => {"$lte" => right_now},
- :limit => limit,
+ :limit => -limit, # In mongo, positive limits are 'soft' and negative are 'hard'
:failed_at => nil,
:sort => [['priority', 1], ['run_at', 1]]
}
View
10 spec/backend/mongo_mapper_job_spec.rb
@@ -12,6 +12,16 @@
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
Please sign in to comment.
Something went wrong with that request. Please try again.