Skip to content
Browse files

passing along the notion of an 'owner' from job to work unit.

  • Loading branch information...
1 parent 28e4477 commit 243ed539ec9d937f959a663dc0bddb2d1816deff @jashkenas jashkenas committed Feb 16, 2011
Showing with 13 additions and 9 deletions.
  1. +8 −7 lib/cloud_crowd/models/job.rb
  2. +3 −2 lib/cloud_crowd/models/work_unit.rb
  3. +2 −0 lib/cloud_crowd/schema.rb
View
15 lib/cloud_crowd/models/job.rb
@@ -21,13 +21,14 @@ class Job < ActiveRecord::Base
named_scope :older_than, lambda {|num| {:conditions => ['updated_at < ?', num.days.ago]} }
# Create a Job from an incoming JSON request, and add it to the queue.
- def self.create_from_request(h)
+ def self.create_from_request(data)
self.create(
- :inputs => h['inputs'].to_json,
- :action => h['action'],
- :options => (h['options'] || {}).to_json,
- :email => h['email'],
- :callback_url => h['callback_url']
+ :inputs => data['inputs'].to_json,
+ :action => data['action'],
+ :owner => data['owner'],
+ :options => (data['options'] || {}).to_json,
+ :email => data['email'],
+ :callback_url => data['callback_url']
)
end
@@ -178,7 +179,7 @@ def gather_outputs_from_work_units
# away.
def queue_for_workers(input=nil)
input ||= JSON.parse(self.inputs)
- input.each {|i| WorkUnit.start(self, action, i, status) }
+ input.each {|i| WorkUnit.start(self, i) }
self
end
View
5 lib/cloud_crowd/models/work_unit.rb
@@ -105,9 +105,10 @@ def self.find_by_worker_name(name)
end
# Convenience method for starting a new WorkUnit.
- def self.start(job, action, input, status)
+ def self.start(job, input)
input = input.to_json unless input.is_a? String
- self.create(:job => job, :action => action, :input => input, :status => status)
+ self.create(:job => job, :action => job.action, :owner => job.owner,
+ :status => job.status, :input => input)
end
# Mark this unit as having finished successfully.
View
2 lib/cloud_crowd/schema.rb
@@ -5,6 +5,7 @@
t.integer "status", :null => false
t.text "inputs", :null => false
t.string "action", :null => false
+ t.string "owner"
t.text "options", :null => false
t.text "outputs"
t.float "time"
@@ -31,6 +32,7 @@
t.integer "job_id", :null => false
t.text "input", :null => false
t.string "action", :null => false
+ t.string "owner"
t.integer "attempts", :default => 0, :null => false
t.integer "node_record_id"
t.integer "worker_pid"

0 comments on commit 243ed53

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