class Box::Office::Booth

Attributes

showing[R]

Public Class Methods

new(showing:) click to toggle source
# File lib/box/office/booth.rb, line 11
def initialize(showing:)
  @showing = showing
end

Public Instance Methods

first_available_opening(conn) { |queue| ... } click to toggle source
# File lib/box/office/booth.rb, line 15
def first_available_opening(conn)
  1.upto(showing.showings) do |idx|
    queue = find_queue(idx)

    Redlock::Client.new([conn]).lock("#{queue.name}-locked", 3000) do |locked|
      if locked && !Janitor.locked?(queue.name) && queue.length < showing.capacity
        yield queue
        return
      end
    end

    next if idx < showing.showings

    raise NoOpenings, "No available openings for #{showing.name}"
  end
end

Private Instance Methods

find_queue(idx) click to toggle source
# File lib/box/office/booth.rb, line 34
def find_queue(idx)
  showing.send(config.reserved, idx)
end