Module: Prebake::AsyncPublisher

Defined in:
lib/prebake/async_publisher.rb

Class Method Summary collapse

Class Method Details

.enqueue(spec, backend) ⇒ Object



19
20
21
# File 'lib/prebake/async_publisher.rb', line 19

def self.enqueue(spec, backend)
  @mutex.synchronize { @pending_specs << [spec, backend] }
end

.reset!Object



15
16
17
# File 'lib/prebake/async_publisher.rb', line 15

def self.reset!
  @mutex.synchronize { @pending_specs.clear }
end

.wait_for_completion(timeout: 120) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/prebake/async_publisher.rb', line 23

def self.wait_for_completion(timeout: 120)
  specs = @mutex.synchronize { @pending_specs.dup }
  return if specs.empty?

  Logger.info "Building #{specs.size} platform gem(s)..."

  # Build serially (Dir.chdir is not thread-safe in Ruby 4.0)
  built_gems = specs.filter_map do |spec, backend|
    build_gem(spec, backend)
  end

  if built_gems.any?
    Logger.info "Pushing #{built_gems.size} gem(s) in background..."

    # Push in parallel (just HTTP, no chdir needed)
    push_threads = built_gems.map do |gem_path, cache_key, checksum, backend|
      Thread.new do
        backend.push(gem_path, cache_key, checksum)
      rescue StandardError => e
        Logger.warn "Push failed for #{cache_key}: #{e.message}"
      ensure
        FileUtils.rm_f(gem_path)
      end
    end

    push_threads.each { |t| t.join(timeout) }
  end

  Logger.info "All pushes complete."

  @mutex.synchronize { @pending_specs.clear }
end