Class: FastlyNsq::Launcher

Inherits:
Object
  • Object
show all
Includes:
SafeThread
Defined in:
lib/fastly_nsq/launcher.rb

Overview

FastlyNsq::Launcher is a lighweight wrapper of a thread manager and heartbeat.

This class is used internally by FastlyNsq::CLI.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SafeThread

#safe_thread, #watchdog

Constructor Details

#initialize(**options) ⇒ Launcher

Returns a new instance of Launcher.



20
21
22
23
24
25
26
27
28
# File 'lib/fastly_nsq/launcher.rb', line 20

def initialize(**options)
  @done = false
  @timeout = options[:timeout] || 5
  @pulse = options[:pulse] || 5
  @logger = options[:logger] || FastlyNsq.logger

  FastlyNsq.manager = FastlyNsq::Manager.new(**options)
  FastlyNsq.fire_event :startup
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



13
14
15
# File 'lib/fastly_nsq/launcher.rb', line 13

def logger
  @logger
end

#pulseObject

Returns the value of attribute pulse.



14
15
16
# File 'lib/fastly_nsq/launcher.rb', line 14

def pulse
  @pulse
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



13
14
15
# File 'lib/fastly_nsq/launcher.rb', line 13

def timeout
  @timeout
end

Instance Method Details

#beatObject



30
31
32
# File 'lib/fastly_nsq/launcher.rb', line 30

def beat
  @heartbeat ||= safe_thread("heartbeat", &method(:start_heartbeat))
end

#managerObject



16
17
18
# File 'lib/fastly_nsq/launcher.rb', line 16

def manager
  FastlyNsq.manager
end

#stopObject



34
35
36
37
38
# File 'lib/fastly_nsq/launcher.rb', line 34

def stop
  @done = true
  manager.terminate(timeout)
  FastlyNsq.fire_event :shutdown
end

#stop_listenersObject



40
41
42
43
# File 'lib/fastly_nsq/launcher.rb', line 40

def stop_listeners
  @done = true
  manager.stop_listeners
end

#stopping?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/fastly_nsq/launcher.rb', line 45

def stopping?
  @done
end