Class: OMQ::Engine::Reconnect

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(engine, endpoint, options) ⇒ Reconnect

Returns a new instance of Reconnect.

Parameters:



26
27
28
29
30
# File 'lib/omq/engine/reconnect.rb', line 26

def initialize(engine, endpoint, options)
  @engine   = engine
  @endpoint = endpoint
  @options  = options
end

Class Method Details

.schedule(endpoint, options, parent_task, engine, delay: nil) ⇒ Object

Parameters:

  • endpoint (String)
  • options (Options)
  • parent_task (Async::Task)
  • engine (Engine)
  • delay (Numeric, nil) (defaults to: nil)

    initial delay (defaults to reconnect_interval)



17
18
19
# File 'lib/omq/engine/reconnect.rb', line 17

def self.schedule(endpoint, options, parent_task, engine, delay: nil)
  new(engine, endpoint, options).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.

Parameters:

  • parent_task (Async::Task)
  • delay (Numeric, nil) (defaults to: nil)

    initial delay override



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