Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* code cleanup / comments

  • Loading branch information...
commit 97862c37db777d039b9bd362f8dbc842b0c21926 1 parent 3a80488
@lpetre lpetre authored bkeepers committed
Showing with 14 additions and 12 deletions.
  1. +13 −11 lib/delayed/backend/datamapper.rb
  2. +1 −1  spec/datamapper_job_spec.rb
View
24 lib/delayed/backend/datamapper.rb
@@ -42,17 +42,19 @@ def self.db_time_now
end
def self.find_available(worker_name, limit = 5, max_run_time = Worker.max_run_time)
- where = "this.run_at <= new Date(#{db_time_now.to_f * 1000}) && (this.locked_at == null || this.locked_at < new Date(#{(db_time_now - max_run_time).to_f * 1000})) || this.locked_by == #{worker_name.to_json}"
- # all(:limit => limit, :failed_at => nil, '$where' => where)
-
- complex = all(:run_at.lte => db_time_now) &
- (( all(:locked_at => nil ) | all(:locked_at.lt => db_time_now - max_run_time)) |
- all(:locked_by => worker_name));
-
- complex.all( :limit => limit,
- :failed_at => nil,
- :order => [:priority.asc, :run_at.asc] )
+ # not yet running
+ running = all(:run_at.lte => db_time_now)
+ # lockable
+ lockable = (
+ # not locked or past the max time
+ ( all(:locked_at => nil ) | all(:locked_at.lt => db_time_now - max_run_time)) |
+
+ # OR locked by our worker
+ all(:locked_by => worker_name))
+
+ # plus some other boring junk
+ (running & lockable).all( :limit => limit, :failed_at => nil, :order => [:priority.asc, :run_at.asc] )
end
# When a worker is exiting, make sure we don't have any locked jobs.
@@ -97,4 +99,4 @@ class JobObserver
end
end
end
-end
+end
View
2  spec/datamapper_job_spec.rb
@@ -51,4 +51,4 @@ def tell
end
end
end
-end
+end

0 comments on commit 97862c3

Please sign in to comment.
Something went wrong with that request. Please try again.