Class: DispatchPolicy::Gate

Inherits:
Object
  • Object
show all
Defined in:
lib/dispatch_policy/gate.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/dispatch_policy/gate.rb', line 15

def name
  @name
end

#partition_byObject (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

#policyObject (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

.registryObject



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.

Raises:

  • (NotImplementedError)


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.

Returns:

  • (Boolean)


39
40
41
# File 'lib/dispatch_policy/gate.rb', line 39

def tracks_inflight?
  false
end