Class: Flamingo::Daemon::WaderProcess

Inherits:
ChildProcess show all
Defined in:
lib/flamingo/daemon/wader_process.rb

Constant Summary collapse

EXIT_CLEAN =

Exit codes

0
EXIT_UNKNOWN_ERROR =

Non-fatal exit code - For transient network errors where a retry is likely to resolve the problem

001
EXIT_MAX_RECONNECTS =
002
EXIT_SERVER_UNAVAILABLE =
003
EXIT_FATAL_RANGE =

1XX is a fatal exit code - Human intervention or a configuration change is necessary to get the wader started

100..199
EXIT_AUTHENTICATION =
100
EXIT_UNKNOWN_STREAM =
101
EXIT_INVALID_PARAMS =
102

Instance Attribute Summary

Attributes inherited from ChildProcess

#pid

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ChildProcess

#kill, #running?, #start

Methods included from TrapKeeper

trap

Class Method Details

.fatal_exit?(status) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/flamingo/daemon/wader_process.rb', line 22

def fatal_exit?(status)
  status && EXIT_FATAL_RANGE.include?(status.exitstatus)
end

Instance Method Details

#register_signal_handlersObject



27
28
29
# File 'lib/flamingo/daemon/wader_process.rb', line 27

def register_signal_handlers
  trap("INT")  { stop }
end

#runObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/flamingo/daemon/wader_process.rb', line 31

def run
  register_signal_handlers
  $0 = 'flamingod-wader'
  config = Flamingo.config
  
  screen_name = config.username
  password    = config.password
  stream      = Stream.get(config.stream)

  @wader = Flamingo::Wader.new(screen_name,password,stream)
  Flamingo.logger.info "Starting wader on pid=#{Process.pid} under pid=#{Process.ppid}"
  
  exit_code = EXIT_CLEAN
  begin
    @wader.run
  rescue => e
    exit_code = error_exit_code(e)
  end
  
  Flamingo.logger.info "Wader pid=#{Process.pid} exited with code #{exit_code}"
  exit(exit_code)
end

#stopObject



54
55
56
# File 'lib/flamingo/daemon/wader_process.rb', line 54

def stop
  @wader.stop
end