Class: PreCapturePool::Builder

Inherits:
Object
  • Object
show all
Defined in:
app/models/pre_capture_pool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(submission) ⇒ Builder

Returns a new instance of Builder.



33
34
35
# File 'app/models/pre_capture_pool.rb', line 33

def initialize(submission)
  @submission = submission
end

Instance Attribute Details

#submissionObject (readonly)

Returns the value of attribute submission.



31
32
33
# File 'app/models/pre_capture_pool.rb', line 31

def submission
  @submission
end

Instance Method Details

#build!Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/models/pre_capture_pool.rb', line 37

def build!
  ActiveRecord::Base.transaction do
    return unless poolable? # rubocop:todo Rails/TransactionExitStatement

    # We find the library creation requests sorted in column order
    # and then walk downstream until we get to the poolable requests.
    # It is these requests that get assigned to a pre-capture pool.
    # We can't jump to the poolable requests directly, as they may not
    # be sorted in column order.
    grouped_requests.each do |_, requests|
      plex = requests.first.order.request_options['pre_capture_plex_level'].to_i
      poolable_requests = requests.flat_map { |request| walk_to_pooled_request(request) }
      pool(poolable_requests, plex)
    end
  end
end