Class: DispatchPolicy::Gate
- Inherits:
-
Object
- Object
- DispatchPolicy::Gate
- Defined in:
- lib/dispatch_policy/gate.rb
Direct Known Subclasses
DispatchPolicy::Gates::AdaptiveConcurrency, DispatchPolicy::Gates::Concurrency, DispatchPolicy::Gates::FairInterleave, DispatchPolicy::Gates::GlobalCap, DispatchPolicy::Gates::Throttle
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#partition_by ⇒ Object
readonly
Returns the value of attribute partition_by.
-
#policy ⇒ Object
readonly
Returns the value of attribute policy.
Class Method Summary collapse
Instance Method Summary collapse
- #configure(**_opts) ⇒ Object
-
#filter(_batch, _context) ⇒ Object
Subclasses must implement.
-
#initialize(policy:, name:, partition_by: nil, **opts) ⇒ Gate
constructor
A new instance of Gate.
-
#partition_key_for(ctx) ⇒ Object
Resolve a partition key for a given context.
-
#tracks_inflight? ⇒ Boolean
Whether this gate keeps an in-flight count that must be released when the job finishes.
Constructor Details
#initialize(policy:, name:, partition_by: nil, **opts) ⇒ Gate
Returns a new instance of Gate.
17 18 19 20 21 22 |
# File 'lib/dispatch_policy/gate.rb', line 17 def initialize(policy:, name:, partition_by: nil, **opts) @policy = policy @name = name @partition_by = partition_by configure(**opts) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/dispatch_policy/gate.rb', line 15 def name @name end |
#partition_by ⇒ Object (readonly)
Returns the value of attribute partition_by.
15 16 17 |
# File 'lib/dispatch_policy/gate.rb', line 15 def partition_by @partition_by end |
#policy ⇒ Object (readonly)
Returns the value of attribute policy.
15 16 17 |
# File 'lib/dispatch_policy/gate.rb', line 15 def policy @policy end |
Class Method Details
.register(name, klass) ⇒ Object
10 11 12 |
# File 'lib/dispatch_policy/gate.rb', line 10 def register(name, klass) registry[name.to_sym] = klass end |
.registry ⇒ Object
6 7 8 |
# File 'lib/dispatch_policy/gate.rb', line 6 def registry @registry ||= {} end |
Instance Method Details
#configure(**_opts) ⇒ Object
24 |
# File 'lib/dispatch_policy/gate.rb', line 24 def configure(**_opts); end |
#filter(_batch, _context) ⇒ Object
Subclasses must implement.
33 34 35 |
# File 'lib/dispatch_policy/gate.rb', line 33 def filter(_batch, _context) raise NotImplementedError end |
#partition_key_for(ctx) ⇒ Object
Resolve a partition key for a given context.
27 28 29 30 |
# File 'lib/dispatch_policy/gate.rb', line 27 def partition_key_for(ctx) return "default" if @partition_by.nil? @partition_by.call(ctx).to_s end |
#tracks_inflight? ⇒ Boolean
Whether this gate keeps an in-flight count that must be released when the job finishes.
39 40 41 |
# File 'lib/dispatch_policy/gate.rb', line 39 def tracks_inflight? false end |