Class: OMQ::Engine::Reconnect
- Inherits:
-
Object
- Object
- OMQ::Engine::Reconnect
- Defined in:
- lib/omq/engine/reconnect.rb
Overview
Schedules reconnect attempts with exponential back-off.
Runs a background task that loops until a connection is established or the engine is closed.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(engine, endpoint, options) ⇒ Reconnect
constructor
A new instance of Reconnect.
-
#run(parent_task, delay: nil) ⇒ void
Spawns a background task that retries the connection with exponential backoff.
Constructor Details
#initialize(engine, endpoint, options) ⇒ Reconnect
Returns a new instance of Reconnect.
26 27 28 29 30 |
# File 'lib/omq/engine/reconnect.rb', line 26 def initialize(engine, endpoint, ) @engine = engine @endpoint = endpoint @options = end |
Class Method Details
.schedule(endpoint, options, parent_task, engine, delay: nil) ⇒ Object
17 18 19 |
# File 'lib/omq/engine/reconnect.rb', line 17 def self.schedule(endpoint, , parent_task, engine, delay: nil) new(engine, endpoint, ).run(parent_task, delay: delay) end |
Instance Method Details
#run(parent_task, delay: nil) ⇒ void
This method returns an undefined value.
Spawns a background task that retries the connection with exponential backoff.
39 40 41 42 43 44 45 46 |
# File 'lib/omq/engine/reconnect.rb', line 39 def run(parent_task, delay: nil) @engine.tasks << parent_task.async(transient: true, annotation: "reconnect #{@endpoint}") do retry_loop(delay: delay) rescue Async::Stop rescue => error @engine.signal_fatal_error(error) end end |