Sha256: 71e39a33098f05241404280c269e7948580ac467851e846de8cd28ebd325300d

Contents?: true

Size: 819 Bytes

Versions: 3

Compression:

Stored size: 819 Bytes

Contents

module Qmore
  class JobReserver
    include Qmore::Attributes
    attr_reader :queues

    def initialize(queues)
      @queues = queues
    end

    def description
      @description ||= @queues.map(&:name).join(', ') + " (qmore)"
    end
    
    def reserve
      realize_queues.each do |q|
        job = q.pop
        return job if job
      end
      
      nil
    end
    
    private
    
    def realize_queues
      queue_names = @queues.collect(&:name)
      real_queues = Qmore.client.queues.counts.collect {|h| h['name'] }
      
      realized_queues = expand_queues(queue_names, real_queues)
      realized_queues = prioritize_queues(get_priority_buckets, realized_queues)
      realized_queues = realized_queues.collect {|q| Qmore.client.queues[q] }
      realized_queues
    end
          
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
qmore-0.5.2 lib/qmore/job_reserver.rb
qmore-0.5.1 lib/qmore/job_reserver.rb
qmore-0.5.0 lib/qmore/job_reserver.rb