app/models/extface/driver.rb in extface-0.3.0 vs app/models/extface/driver.rb in extface-0.4.0
- old
+ new
@@ -44,22 +44,35 @@
handle(buffer)
end
def push(buffer)
if @job
- Timeout.timeout(Extface.device_timeout) do
- Extface.redis_block do |r|
- r.subscribe(@job.id) do |on| #blocking until delivered
- on.subscribe do |channel, subscriptions|
- @job.rpush buffer
- logger.debug "--> #{buffer.bytes.map{ |b| '%02X' % b }.join(' ')}" if development?
+ #retry if current device job is not @job (waiting on queue)
+ wait_on_queue = false
+ begin
+ if current_device_job = device.jobs(true).active.try(:first)
+ if current_device_job != @job
+ wait_on_queue = true
+ p "#### current_job is not first_on_queue"
+ end
+ end
+ Timeout.timeout(Extface.device_timeout) do
+ Extface.redis_block do |r|
+ r.subscribe(@job.id) do |on| #blocking until delivered
+ on.subscribe do |channel, subscriptions|
+ @job.rpush buffer
+ logger.debug "--> #{buffer.bytes.map{ |b| '%02X' % b }.join(' ')}" if development?
+ end
+ on.message do |event, data|
+ r.unsubscribe
+ @job.connected!
+ end
end
- on.message do |event, data|
- r.unsubscribe
- @job.connected!
- end
end
end
+ rescue Timeout::Error
+ p "###########3 timeout err"
+ retry if wait_on_queue
end
else
raise "No job given"
end
end