Class: Tengine::Core::Config::HeartbeatWatcher
- Inherits:
-
Support::Config::Definition::Suite
- Object
- Support::Config::Definition::Suite
- Tengine::Core::Config::HeartbeatWatcher
- Defined in:
- lib/tengine/core/config/heartbeat_watcher.rb
Defined Under Namespace
Classes: AmqpConnection, LoggerConfig, Process
Class Method Summary collapse
-
.[](hash_or_suite) ⇒ Object
この辺は以前のTengine::Core::Configとの互換のために用意してあります.
- .default_hash ⇒ Object (also: skelton_hash)
- .parse(args) ⇒ Object
- .parse_to_hash(args) ⇒ Object
Instance Method Summary collapse
- #build ⇒ Object
- #heartbeat_enabled? ⇒ Boolean
- #heartbeat_period ⇒ Object
-
#initialize(hash_or_filepath = nil) ⇒ HeartbeatWatcher
constructor
A new instance of HeartbeatWatcher.
- #load_file(filepath) ⇒ Object
- #setup_loggers ⇒ Object
Constructor Details
#initialize(hash_or_filepath = nil) ⇒ HeartbeatWatcher
Returns a new instance of HeartbeatWatcher.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tengine/core/config/heartbeat_watcher.rb', line 52 def initialize(hash_or_filepath = nil) build if respond_to?(:build) case hash_or_filepath when Hash then if config = hash_or_filepath[:config] load_file(config) else load(hash_or_filepath) end when String then load_file(hash_or_filepath) end end |
Class Method Details
.[](hash_or_suite) ⇒ Object
この辺は以前のTengine::Core::Configとの互換のために用意してあります
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tengine/core/config/heartbeat_watcher.rb', line 19 def [](hash_or_suite) case hash_or_suite when Tengine::Core::Config::HeartbeatWatcher then hash_or_suite when Hash then result = Tengine::Core::Config::HeartbeatWatcher.new result.load(hash_or_suite) result else raise "unsupported class: #{hash_or_suite.class.inspect}" end end |
.default_hash ⇒ Object Also known as: skelton_hash
31 32 33 |
# File 'lib/tengine/core/config/heartbeat_watcher.rb', line 31 def default_hash new.to_hash end |
.parse(args) ⇒ Object
44 45 46 47 48 |
# File 'lib/tengine/core/config/heartbeat_watcher.rb', line 44 def parse(args) config = new config.parse!(args) config end |
.parse_to_hash(args) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/tengine/core/config/heartbeat_watcher.rb', line 36 def parse_to_hash(args) config = new config.parse!(args) result = new result.config = config.config result.to_hash end |
Instance Method Details
#build ⇒ Object
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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/tengine/core/config/heartbeat_watcher.rb', line 76 def build <<EOS Usage: tengine_heartbeat_watchd [-k action] [-f path_to_config] [-D process_daemon] [-o mq_conn_host] [-p mq_conn_port] [-u mq_conn_user] [-s mq_conn_pass] [-e mq_exchange_name] [-q mq_queue_name] [-G heartbeat_hbw_interval] EOS field(:action, "start|stop", :type => :string, :default => "start") load_config(:config, "path/to/config_file", :type => :string) add(:process, Tengine::Core::Config::HeartbeatWatcher::Process) field(:db, "settings to connect to db", :type => :hash, :default => Tengine::Core::Config::DB::DEFAULT_SETTINGS) group(:heartbeat) do add(:core , Tengine::Core::Config::Core::Heartbeat) add(:job , Tengine::Core::Config::Core::Heartbeat, :defaults => {:interval => 5, :expire => 20}) add(:hbw , Tengine::Core::Config::Core::Heartbeat) add(:resourcew, Tengine::Core::Config::Core::Heartbeat) add(:atd , Tengine::Core::Config::Core::Heartbeat) end group(:event_queue, :hidden => true) do add(:connection, AmqpConnection) add(:exchange , Tengine::Support::Config::Amqp::Exchange, :defaults => {:name => 'tengine_event_exchange'}) add(:queue , Tengine::Support::Config::Amqp::Queue , :defaults => {:name => 'tengine_event_queue'}) end add(:log_common, Tengine::Support::Config::Logger, :defaults => { :rotation => 3 , :rotation_size => 1024 * 1024, :level => 'info' , }) add(:application_log, Tengine::Core::Config::HeartbeatWatcher::LoggerConfig, :parameters => {:logger_name => "application"}, :dependencies => { :process_config => :process, :log_common => :log_common,}){ self.formatter = lambda{|level, t, prog, msg| "#{t.iso8601} #{level} #{@process_identifier} #{msg}\n"} } add(:process_stdout_log, Tengine::Core::Config::HeartbeatWatcher::LoggerConfig, :parameters => {:logger_name => "#{File.basename($PROGRAM_NAME)}_#{::Process.pid}_stdout"}, :dependencies => { :process_config => :process, :log_common => :log_common,}){ self.formatter = lambda{|level, t, prog, msg| "#{t.iso8601} STDOUT #{@process_identifier} #{msg}\n"} } add(:process_stderr_log, Tengine::Core::Config::HeartbeatWatcher::LoggerConfig, :parameters => {:logger_name => "#{File.basename($PROGRAM_NAME)}_#{::Process.pid}_stderr"}, :dependencies => { :process_config => :process, :log_common => :log_common,}, :defaults => { :output => proc{ process_config.daemon ? "./log/#{logger_name}.log" : "STDERR" }}){ self.formatter = lambda{|level, t, prog, msg| "#{t.iso8601} STDERR #{@process_identifier} #{msg}\n"} } separator("\nGeneral:") field(:verbose, "Show detail to this command", :type => :boolean) __action__(:version, "show version"){ STDOUT.puts Tengine::Core.version.to_s; exit } __action__(:dump_skelton, "dump skelton of config"){ STDOUT.puts YAML.dump(root.to_hash); exit } __action__(:help , "show this help message"){ STDOUT.puts option_parser.help; exit } mapping({ [:action] => :k, [:config] => :f, [:process, :daemon] => :D, [:event_queue, :connection, :host] => :o, [:event_queue, :connection, :port] => :p, [:event_queue, :connection, :user] => :u, [:event_queue, :connection, :pass] => :s, [:event_queue, :exchange , :name] => :e, [:event_queue, :queue , :name] => :q, [:heartbeat, :hbw, :interval] => :G, [:verbose] => :V, [:version] => :v, [:help] => :h }) end |
#heartbeat_enabled? ⇒ Boolean
167 168 169 |
# File 'lib/tengine/core/config/heartbeat_watcher.rb', line 167 def heartbeat_enabled? heartbeat_period > 0 end |
#heartbeat_period ⇒ Object
162 163 164 165 |
# File 'lib/tengine/core/config/heartbeat_watcher.rb', line 162 def heartbeat_period # [:][:heartbeat_period].to_i heartbeat.interval.to_i end |
#load_file(filepath) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/tengine/core/config/heartbeat_watcher.rb', line 65 def load_file(filepath) super rescue Exception => e msg = e. unless msg.include?(filepath) msg = "#{msg} in #{filepath}" end raise Tengine::Core::ConfigError, msg end |
#setup_loggers ⇒ Object
210 211 212 213 214 215 216 217 218 219 |
# File 'lib/tengine/core/config/heartbeat_watcher.rb', line 210 def setup_loggers Tengine.logger = application_log.new_logger Tengine::Core.stdout_logger = process_stdout_log.new_logger Tengine::Core.stderr_logger = process_stderr_log.new_logger Tengine::Core.stdout_logger.info("#{self.class.name}#setup_loggers complete") rescue Exception Tengine::Core.stderr_logger.info("#{self.class.name}#setup_loggers failure") raise end |