Class: Julewire::Ractor::Fanout

Inherits:
Object
  • Object
show all
Defined in:
lib/julewire/ractor/fanout.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(destinations:, name: :ractor_fanout, on_failure: nil) ⇒ Fanout

Returns a new instance of Fanout.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/julewire/ractor/fanout.rb', line 8

def initialize(destinations:, name: :ractor_fanout, on_failure: nil)
  @name = Core::Destinations.normalize_name(name)
  raise ArgumentError, "destinations must be an Array" unless destinations.instance_of?(Array)

  @destinations = destinations.map { normalize_destination(it) }
  raise ArgumentError, "destinations must not be empty" if @destinations.empty?

  Core::Validation.validate_callable!(on_failure, name: :on_failure, allow_nil: true)
  @on_failure = on_failure
  @health = Core::Integration::DestinationHealth.new(counter_keys: [], failure_counter: nil)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/julewire/ractor/fanout.rb', line 6

def name
  @name
end

Instance Method Details

#after_fork!Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/julewire/ractor/fanout.rb', line 35

def after_fork!
  @health.recover_if_successful do
    @destinations.each do |destination|
      destination.after_fork! if destination.respond_to?(:after_fork!)
    rescue StandardError => e
      record_failure(e, action: :after_fork, destination: destination.name)
    end
  end
  self
end

#close(timeout: nil) ⇒ Object



31
32
33
# File 'lib/julewire/ractor/fanout.rb', line 31

def close(timeout: nil)
  call_lifecycle(:close, timeout: timeout)
end

#emit(record) ⇒ Object



20
21
22
23
24
25
# File 'lib/julewire/ractor/fanout.rb', line 20

def emit(record)
  @health.recover_if_successful do
    @destinations.each { emit_to_destination(it, record) }
  end
  nil
end

#flush(timeout: nil) ⇒ Object



27
28
29
# File 'lib/julewire/ractor/fanout.rb', line 27

def flush(timeout: nil)
  call_lifecycle(:flush, timeout: timeout)
end

#healthObject



48
49
50
51
52
53
54
# File 'lib/julewire/ractor/fanout.rb', line 48

def health
  destinations = @destinations.to_h { [it.name, destination_health(it)] }
  @health.snapshot(
    destinations: destinations,
    status: health_status(destinations)
  )
end

#resource_identityObject



46
# File 'lib/julewire/ractor/fanout.rb', line 46

def resource_identity = self