Class: TCB::EventBus::ShutdownStrategy
- Inherits:
-
Object
- Object
- TCB::EventBus::ShutdownStrategy
- Defined in:
- lib/tcb/event_bus/shutdown_strategy.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(event_bus:, drain:, timeout:) ⇒ ShutdownStrategy
constructor
A new instance of ShutdownStrategy.
- #publish(event) ⇒ Object
- #shutdown? ⇒ Boolean
- #subscribe(event_class, &block) ⇒ Object
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
#execute ⇒ Object
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
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
21 22 23 |
# File 'lib/tcb/event_bus/shutdown_strategy.rb', line 21 def shutdown? true end |
#subscribe(event_class, &block) ⇒ Object
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 |