Class: Smith::Tool::ExecutionBatch

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Defined in:
lib/smith/tool/execution_batch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExecutionBatch

Returns a new instance of ExecutionBatch.



22
23
24
25
26
27
28
29
# File 'lib/smith/tool/execution_batch.rb', line 22

def initialize(...)
  super
  @state = ExecutionBatchState.new(requests:)
  @mutex = Mutex.new
  initialize_failure_queues
  @host_admitted = false
  @host_admission_required = context.fetch(:current_invocation_batch_admitter) && requests.any?
end

Instance Attribute Details

#capture_failuresObject (readonly)

Returns the value of attribute capture_failures.



20
21
22
# File 'lib/smith/tool/execution_batch.rb', line 20

def capture_failures
  @capture_failures
end

#fatal_failuresObject (readonly)

Returns the value of attribute fatal_failures.



20
21
22
# File 'lib/smith/tool/execution_batch.rb', line 20

def fatal_failures
  @fatal_failures
end

#notification_failuresObject (readonly)

Returns the value of attribute notification_failures.



20
21
22
# File 'lib/smith/tool/execution_batch.rb', line 20

def notification_failures
  @notification_failures
end

#terminal_failuresObject (readonly)

Returns the value of attribute terminal_failures.



20
21
22
# File 'lib/smith/tool/execution_batch.rb', line 20

def terminal_failures
  @terminal_failures
end

Instance Method Details

#admission_for(tool_call) ⇒ Object



35
# File 'lib/smith/tool/execution_batch.rb', line 35

def admission_for(tool_call) = call_admissions[tool_call]

#claim_dispatch!(tool_call) ⇒ Object



41
# File 'lib/smith/tool/execution_batch.rb', line 41

def claim_dispatch!(tool_call) = @state.claim_dispatch!(tool_call)

#claim_failure_request(tool_call) ⇒ Object



68
# File 'lib/smith/tool/execution_batch.rb', line 68

def claim_failure_request(tool_call) = @state.claim_failure_request(tool_call)

#claim_unsettled_requestObject



70
# File 'lib/smith/tool/execution_batch.rb', line 70

def claim_unsettled_request = @state.claim_unsettled_request

#complete_failure_notification!(tool_call) ⇒ Object



72
# File 'lib/smith/tool/execution_batch.rb', line 72

def complete_failure_notification!(tool_call) = @state.complete_failure_notification!(tool_call)

#dispatch_for(tool_call) ⇒ Object



37
# File 'lib/smith/tool/execution_batch.rb', line 37

def dispatch_for(tool_call) = requests.key?(tool_call) ? tool_call : dispatch_calls[tool_call]

#host_admitted?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/smith/tool/execution_batch.rb', line 64

def host_admitted?
  @mutex.synchronize { @host_admitted }
end

#mark_executed!(tool_call, claim:) ⇒ Object



56
# File 'lib/smith/tool/execution_batch.rb', line 56

def mark_executed!(tool_call, claim:) = @state.mark_executed!(tool_call, claim:)

#mark_host_admitted!Object



60
61
62
# File 'lib/smith/tool/execution_batch.rb', line 60

def mark_host_admitted!
  @mutex.synchronize { @host_admitted = true }
end

#mark_started!(tool_call, claim:) ⇒ Object



54
# File 'lib/smith/tool/execution_batch.rb', line 54

def mark_started!(tool_call, claim:) = @state.mark_started!(tool_call, claim:)

#release_failure_notification!(tool_call, state) ⇒ Object



74
# File 'lib/smith/tool/execution_batch.rb', line 74

def release_failure_notification!(tool_call, state) = @state.release_failure_notification!(tool_call, state)

#request_for(tool_call) ⇒ Object



31
# File 'lib/smith/tool/execution_batch.rb', line 31

def request_for(tool_call) = requests[tool_call]

#settle!Object



76
# File 'lib/smith/tool/execution_batch.rb', line 76

def settle! = call_reservation&.settle!

#source_for(tool_call) ⇒ Object



39
# File 'lib/smith/tool/execution_batch.rb', line 39

def source_for(tool_call) = source_calls_by_dispatch[tool_call]

#started?(tool_call) ⇒ Boolean

Returns:

  • (Boolean)


58
# File 'lib/smith/tool/execution_batch.rb', line 58

def started?(tool_call) = @state.started?(tool_call)

#target_for(tool_call) ⇒ Object



33
# File 'lib/smith/tool/execution_batch.rb', line 33

def target_for(tool_call) = targets[tool_call]

#verify_dispatch!(tool_call, current_tool:, claim:) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/smith/tool/execution_batch.rb', line 43

def verify_dispatch!(tool_call, current_tool:, claim:)
  request = requests.fetch(tool_call)
  target = targets.fetch(tool_call)
  return if dispatch_admitted? &&
            @state.dispatch_claimed?(tool_call, claim) &&
            target_unchanged?(current_tool, target, request) &&
            call_unchanged?(tool_call, request)

  raise ToolDispatchRejected, "admitted tool invocation changed before dispatch"
end