Class: Kettle::Family::CommandRunner::OtpCoordinator

Inherits:
Object
  • Object
show all
Defined in:
lib/kettle/family/command_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(input: $stdin, output: $stdout, queue_total: nil, secrets_provider: nil) ⇒ OtpCoordinator

Returns a new instance of OtpCoordinator.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kettle/family/command_runner.rb', line 14

def initialize(input: $stdin, output: $stdout, queue_total: nil, secrets_provider: nil)
  @input = input
  @output = output
  @secrets_provider = secrets_provider
  @mutex = Mutex.new
  @condition = ConditionVariable.new
  @prompting = false
  @queue_closed = false
  @generation = 0
  @completed_generation = nil
  @response = nil
  @queued_count = 0
  @queue_total = queue_total
end

Instance Method Details

#queue_total=(value) ⇒ Object



29
30
31
32
33
# File 'lib/kettle/family/command_runner.rb', line 29

def queue_total=(value)
  @mutex.synchronize do
    @queue_total = value
  end
end

#request(member_name:, chunk:) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/kettle/family/command_runner.rb', line 35

def request(member_name:, chunk:)
  generation = nil
  @mutex.synchronize do
    @condition.wait(@mutex) while @prompting && @queue_closed

    if @prompting
      generation = @generation
      @queued_count += 1
      render_queue_status_locked
      return wait_for_response(generation)
    end

    @prompting = true
    @queue_closed = false
    @queued_count = 1
    @generation += 1
    generation = @generation
    start_prompt_locked(member_name: member_name)
  end

  response = read_response(chunk: chunk)
  close_queue
  @mutex.synchronize do
    @response = response
    @completed_generation = generation
    @prompting = false
    @queue_closed = false
    @condition.broadcast
    response
  end
end