Skip to content

Commit

Permalink
node_record_id may be safer than worker_pid.
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Mar 10, 2011
1 parent 963e21b commit 8788d47
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 2 deletions.
1 change: 0 additions & 1 deletion lib/cloud_crowd/models/node_record.rb
Expand Up @@ -41,7 +41,6 @@ def self.check_in(params, request)
# If the Node responds that it's overloaded, we mark it as busy. Returns # If the Node responds that it's overloaded, we mark it as busy. Returns
# true if the WorkUnit was dispatched successfully. # true if the WorkUnit was dispatched successfully.
def send_work_unit(unit) def send_work_unit(unit)
return false if unit.worker_pid #FIXME: Horrible hack.
result = node['/work'].post(:work_unit => unit.to_json) result = node['/work'].post(:work_unit => unit.to_json)
unit.assign_to(self, JSON.parse(result.body)['pid']) unit.assign_to(self, JSON.parse(result.body)['pid'])
touch && true touch && true
Expand Down
2 changes: 1 addition & 1 deletion lib/cloud_crowd/models/work_unit.rb
Expand Up @@ -81,7 +81,7 @@ def self.distribute_to_nodes
# were none available. # were none available.
def self.reserve_available(options={}) def self.reserve_available(options={})
reservation = ActiveSupport::SecureRandom.random_number(MAX_RESERVATION) reservation = ActiveSupport::SecureRandom.random_number(MAX_RESERVATION)
conditions = "reservation is null and worker_pid is null and status in (#{INCOMPLETE.join(',')}) and #{options[:conditions]}" conditions = "reservation is null and node_record_id is null and status in (#{INCOMPLETE.join(',')}) and #{options[:conditions]}"
any = WorkUnit.update_all("reservation = #{reservation}", conditions, options) > 0 any = WorkUnit.update_all("reservation = #{reservation}", conditions, options) > 0
any && reservation any && reservation
end end
Expand Down

0 comments on commit 8788d47

Please sign in to comment.