Class: DispatchPolicy::Gates::GlobalCap

Inherits:
DispatchPolicy::Gate show all
Defined in:
lib/dispatch_policy/gates/global_cap.rb

Instance Attribute Summary

Attributes inherited from DispatchPolicy::Gate

#name, #partition_by, #policy

Instance Method Summary collapse

Methods inherited from DispatchPolicy::Gate

#initialize, #partition_key_for, register, registry

Constructor Details

This class inherits a constructor from DispatchPolicy::Gate

Instance Method Details

#configure(max:) ⇒ Object



6
7
8
# File 'lib/dispatch_policy/gates/global_cap.rb', line 6

def configure(max:)
  @max = max
end

#filter(batch, context) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/dispatch_policy/gates/global_cap.rb', line 14

def filter(batch, context)
  limit     = resolve(@max, nil).to_i
  in_flight = PartitionInflightCount.total_for(policy_name: policy.name, gate_name: name)
  capacity  = [ limit - in_flight, 0 ].max
  head      = batch.first(capacity)
  context.record_partitions(head.map { |s| [ s, "default" ] }, gate: name)
  head
end

#tracks_inflight?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/dispatch_policy/gates/global_cap.rb', line 10

def tracks_inflight?
  true
end