Class: TCB::EventBus::ShutdownStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/tcb/event_bus/shutdown_strategy.rb

Instance Method Summary collapse

Constructor Details

#initialize(event_bus:, drain:, timeout:) ⇒ ShutdownStrategy

Returns a new instance of ShutdownStrategy.



6
7
8
9
10
11
# File 'lib/tcb/event_bus/shutdown_strategy.rb', line 6

def initialize(event_bus:, drain:, timeout:)
  @event_bus = event_bus
  @drain = drain
  @timeout = timeout
  @start_time = Time.now
end

Instance Method Details

#executeObject



25
26
27
28
29
30
31
32
33
# File 'lib/tcb/event_bus/shutdown_strategy.rb', line 25

def execute
  emit_shutdown_event(:initiated)

  if @drain
    drain_with_timeout
  else
    force_terminate
  end
end

#publish(event) ⇒ Object

Raises:



13
14
15
# File 'lib/tcb/event_bus/shutdown_strategy.rb', line 13

def publish(event)
  raise ShutdownError, "Cannot publish events after shutdown"
end

#shutdown?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/tcb/event_bus/shutdown_strategy.rb', line 21

def shutdown?
  true
end

#subscribe(event_class, &block) ⇒ Object

Raises:



17
18
19
# File 'lib/tcb/event_bus/shutdown_strategy.rb', line 17

def subscribe(event_class, &block)
  raise ShutdownError, "Cannot subscribe after shutdown"
end