Module: Nanite::CommonConfig

Defined in:
lib/nanite/config.rb

Instance Method Summary collapse

Instance Method Details

#setup_common_options(opts, options, type) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/nanite/config.rb', line 46

def setup_common_options(opts, options, type)
  opts.version = Nanite::VERSION

  opts.on("-i", "--irb-console", "Start #{type} in irb console mode.") do |console|
    options[:console] = 'irb'
  end

  opts.on("-u", "--user USER", "Specify the rabbitmq username.") do |user|
    options[:user] = user
  end

  opts.on("-h", "--host HOST", "Specify the rabbitmq hostname.") do |host|
    options[:host] = host
  end

  opts.on("-P", "--port PORT", "Specify the rabbitmq PORT, default 5672.") do |port|
    options[:port] = port
  end

  opts.on("-p", "--pass PASSWORD", "Specify the rabbitmq password") do |pass|
    options[:pass] = pass
  end

  opts.on("-t", "--token IDENITY", "Specify the #{type} identity.") do |ident|
    options[:identity] = ident
  end

  opts.on("-v", "--vhost VHOST", "Specify the rabbitmq vhost") do |vhost|
    options[:vhost] = vhost
  end

  opts.on("-s", "--secure", "Use Security features of rabbitmq to restrict nanites to themselves") do
    options[:secure] = true
  end

  opts.on("-f", "--format FORMAT", "The serialization type to use for transfering data. Can be marshal, json or yaml. Default is marshal") do |fmt|
    options[:format] = fmt.to_sym
  end

  opts.on("-d", "--daemonize", "Run #{type} as a daemon") do |d|
    options[:daemonize] = true
  end
  
  opts.on("--pid-dir PATH", "Specify the pid path, only used with daemonize") do |dir|
    options[:pid_dir] = dir
  end

  opts.on("-l", "--log-level LEVEL", "Specify the log level (fatal, error, warn, info, debug). Default is info") do |level|
    options[:log_level] = level
  end
  
  opts.on("--log-dir PATH", "Specify the log path") do |dir|
    options[:log_dir] = dir
  end

  opts.on("--tag TAG", "Specify a tag.  Can issue multiple times.") do |tag|
    options[:tag] ||= []
    options[:tag] << tag
  end

  opts.on("--version", "Show the nanite version number") do |res|
    puts "Nanite Version #{opts.version}"
    exit
  end
end

#setup_mapper_options(opts, options) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/nanite/config.rb', line 17

def setup_mapper_options(opts, options)
  setup_common_options(opts, options, 'mapper')

  opts.on("-a", "--agent-timeout TIMEOUT", "How long to wait before an agent is considered to be offline and thus removed from the list of available agents.") do |timeout|
    options[:agent_timeout] = timeout
  end

  opts.on("-r", "--offline-redelivery-frequency", "The frequency in seconds that messages stored in the offline queue will be retrieved for attempted redelivery to the nanites. Default is 10 seconds.") do |frequency|
    options[:offline_redelivery_frequency] = frequency
  end

  opts.on("--persistent", "Instructs the AMQP broker to save messages to persistent storage so that they aren't lost when the broker is restarted. Can be overriden on a per-message basis using the request and push methods.") do
    options[:persistent] = true
  end

  opts.on("--offline-failsafe", "Store messages in an offline queue when all the nanites are offline. Messages will be redelivered when nanites come online. Can be overriden on a per-message basis using the request methods.") do
    options[:offline_failsafe] = true
  end
  
  opts.on("--redis HOST_PORT", "Use redis as the agent state storage in the mapper: --redis 127.0.0.1:6379; missing host and/or port will be filled with defaults if colon is present") do |redis|
    redishost, redisport = redis.split(':')
    redishost = '127.0.0.1' if (redishost.nil? || redishost.empty?)
    redisport = '6379' if (redishost.nil? || redishost.empty?)
    redis = "#{redishost}:#{redisport}"
    options[:redis] = redis
  end
  
end