Skip to content

Commit

Permalink
Adding very important indexes. Can't believe I forgot them
Browse files Browse the repository at this point in the history
  • Loading branch information
zbelzer committed Feb 25, 2010
1 parent 80c2ee7 commit 770373a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/delayed/backend/mongo_mapper.rb
Expand Up @@ -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
Expand All @@ -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]]
}
Expand Down
10 changes: 10 additions & 0 deletions spec/backend/mongo_mapper_job_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 770373a

Please sign in to comment.