Sha256: aadee386828bbc3f69f04b3eb58f0b0c6788fbfe4260e792ddc3a149ff16b52c
Contents?: true
Size: 1.02 KB
Versions: 2
Compression:
Stored size: 1.02 KB
Contents
module CloudCrowd module Helpers module Resources def current_job @job ||= Job.find_by_id(params[:job_id]) or raise Sinatra::NotFound end def current_work_unit @work_unit ||= WorkUnit.find_by_id(params[:work_unit_id]) or raise Sinatra::NotFound end # Try to fetch a work unit from the queue. If none are pending, respond # with no content. def dequeue_work_unit(offset=0) handle_conflicts do unit = WorkUnit.dequeue(offset) return status(204) && '' unless unit unit.to_json end end # We're using ActiveRecords optimistic locking, so stale work units # may sometimes arise. handle_conflicts responds with a the HTTP status # code of your choosing if the update failed to be applied. def handle_conflicts(code=204) begin yield rescue ActiveRecord::StaleObjectError => e return status(code) && '' end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
documentcloud-cloud-crowd-0.0.3 | lib/cloud_crowd/helpers/resources.rb |
documentcloud-cloud-crowd-0.0.4 | lib/cloud_crowd/helpers/resources.rb |