Sha256: e225b50a99031a12fd3334d7d8f58105159856e262dd9012c16b6980505f27bf

Contents?: true

Size: 883 Bytes

Versions: 1

Compression:

Stored size: 883 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 prep_for_work!
      # nothing here on purpose
    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

1 entries across 1 versions & 1 rubygems

Version Path
qmore-0.5.3 lib/qmore/job_reserver.rb