lib/cloud_crowd/models/job.rb in documentcloud-cloud-crowd-0.2.0 vs lib/cloud_crowd/models/job.rb in documentcloud-cloud-crowd-0.2.1
- old
+ new
@@ -13,12 +13,11 @@
before_validation_on_create :set_initial_status
after_create :queue_for_workers
before_destroy :cleanup_assets
- # Create a Job from an incoming JSON or XML request, and add it to the queue.
- # TODO: Think about XML support.
+ # Create a Job from an incoming JSON request, and add it to the queue.
def self.create_from_request(h)
self.create(
:inputs => h['inputs'].to_json,
:action => h['action'],
:options => (h['options'] || {}).to_json,
@@ -39,11 +38,12 @@
fire_callback if callback_url
end
self
end
- # Transition this Job's status to the appropriate next status.
+ # Transition this Job's current status to the appropriate next one, based
+ # on the state of the WorkUnits and the nature of the Action.
def set_next_status
update_attribute(:status,
any_work_units_failed? ? FAILED :
self.splitting? ? PROCESSING :
self.mergeable? ? MERGING :
@@ -64,11 +64,12 @@
rescue RestClient::Exception => e
puts "Failed to fire job callback. Hmmm, what should happen here?"
end
end
- # Cleaning up after a job will remove all of its files from S3. Destroying
- # a Job calls cleanup_assets first.
+ # Cleaning up after a job will remove all of its files from S3 or the
+ # filesystem. Destroying a Job will cleanup_assets first. Run this in a
+ # separate thread to get out of the transaction's way.
# TODO: Convert this into a 'cleanup' work unit that gets run by a worker.
def cleanup_assets
AssetStore.new.cleanup(self)
end
\ No newline at end of file