Class: AppInfoBase
- Includes:
- Benchmark, Singleton
- Defined in:
- lib/mrpin/core/app_info/app_info_base.rb
Instance Attribute Summary collapse
-
#boot_time ⇒ Object
readonly
Returns the value of attribute boot_time.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
readonly
Properties.
-
#managers_bundles_map ⇒ Object
readonly
Returns the value of attribute managers_bundles_map.
-
#managers_list ⇒ Object
readonly
Returns the value of attribute managers_list.
-
#managers_with_json_list ⇒ Object
readonly
Returns the value of attribute managers_with_json_list.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #call_in_all_managers(method_name, delay_between_calls = 0.0) ⇒ Object
- #call_in_all_managers_with_benchmark(benchmark_name, method_name, exit_on_error = true) ⇒ Object
- #cleanup_data ⇒ Object
- #host ⇒ Object
-
#initialize(options = nil) ⇒ AppInfoBase
constructor
A new instance of AppInfoBase.
- #is_server_on_maintenance? ⇒ Boolean
- #on_config_updated ⇒ Object
- #on_server_error(message, exception = nil, request = nil, player_id = nil) ⇒ Object
- #on_server_shutdown ⇒ Object
- #post_init ⇒ Object
- #server_name ⇒ Object
Constructor Details
#initialize(options = nil) ⇒ AppInfoBase
Returns a new instance of AppInfoBase.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 185 def initialize( = nil) init_logger begin self.state = EAppState::EAS_INIT_CONFIG self.state = EAppState::EAS_INIT_MANAGERS rescue Exception => e on_server_error(e.to_s, e) @logger.error "can't start server with error #{e}." sleep 60 exit end at_exit do on_server_shutdown end end |
Instance Attribute Details
#boot_time ⇒ Object (readonly)
Returns the value of attribute boot_time.
17 18 19 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 17 def boot_time @boot_time end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
19 20 21 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 19 def config @config end |
#logger ⇒ Object (readonly)
Properties
10 11 12 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 10 def logger @logger end |
#managers_bundles_map ⇒ Object (readonly)
Returns the value of attribute managers_bundles_map.
15 16 17 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 15 def managers_bundles_map @managers_bundles_map end |
#managers_list ⇒ Object (readonly)
Returns the value of attribute managers_list.
12 13 14 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 12 def managers_list @managers_list end |
#managers_with_json_list ⇒ Object (readonly)
Returns the value of attribute managers_with_json_list.
13 14 15 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 13 def managers_with_json_list @managers_with_json_list end |
#state ⇒ Object
Returns the value of attribute state.
21 22 23 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 21 def state @state end |
Instance Method Details
#call_in_all_managers(method_name, delay_between_calls = 0.0) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 246 def call_in_all_managers(method_name, delay_between_calls = 0.0) result = [] @managers_list.each do |manager| next unless manager.respond_to?(method_name) begin manager.send(method_name) if delay_between_calls > 0 sleep(delay_between_calls) end rescue Exception => e on_server_error("Error on #{__method__}: #{e.to_s}", e) result << e end end result end |
#call_in_all_managers_with_benchmark(benchmark_name, method_name, exit_on_error = true) ⇒ Object
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 270 def call_in_all_managers_with_benchmark(benchmark_name, method_name, exit_on_error = true) result = [] white_spaces_count = 50 spaces = ' ' * white_spaces_count benchmark("#{benchmark_name}\n#{spaces}#{CAPTION}", white_spaces_count, FORMAT) do |benchmark| @managers_list.each do |manager| benchmark.report("#{manager.class.name}") do begin next unless manager.respond_to?(method_name) manager.send(method_name) rescue Exception => e on_server_error("Error on #{__method__}: #{e.to_s}", e) result << e end end end end if !result.empty? && exit_on_error result.each do |e| on_server_error(e.to_s, e) end exit end result end |
#cleanup_data ⇒ Object
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 377 def cleanup_data result = nil errors = call_in_all_managers('cleanup_data') errors.map!(&:to_s) if errors.empty? result = get_response_ok else result = get_response_error(errors) end result end |
#host ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 66 def host result = nil if !@config.nil? && !@config.host.nil? result = @config.host end if result.blank? @logger.warn('your forgot setup domain name in AppConfig') end if Rails.env.development? result = 'localhost:3000' end result end |
#is_server_on_maintenance? ⇒ Boolean
96 97 98 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 96 def is_server_on_maintenance? @state == EAppState::EAS_MAINTENANCE end |
#on_config_updated ⇒ Object
119 120 121 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 119 def on_config_updated init_config end |
#on_server_error(message, exception = nil, request = nil, player_id = nil) ⇒ Object
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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 125 def on_server_error(, exception = nil, request = nil, player_id = nil) request_class = request.class.to_s player_id ||= 'unknown' exception ||= Exception.new() stacktrace = exception.backtrace stacktrace = caller if stacktrace.nil? = '' += "\nerror message: #{message}" unless request.nil? += "\nerror request: #{request}" += "\nerror request class: #{request.class}" end if Rails.env.development? += "\nerror player_id: #{player_id}" unless player_id.nil? += "\nerror stack trace: #{stacktrace}" end @logger.error() if Rails.env.production? md5 = Digest::MD5.hexdigest(request_class.to_s + .to_s) error = ErrorServerBase.where(md5: md5).first if error.nil? #create error = ErrorServerBase.new error.first_error_at = Time.now.to_i error. = UtilsString.to_utf8() error.request_class = request_class error.md5 = md5 end player_errors_count = error.players_ids_map[player_id] || 0 error.last_error_at = Time.now.to_i error.players_ids_map[player_id] = player_errors_count + 1 error.throws_count += 1 error.players_count = error.players_ids_map.size error.stack_trace = stacktrace error.save! end end |
#on_server_shutdown ⇒ Object
105 106 107 108 109 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 105 def on_server_shutdown self.state = EAppState::EAS_SHUTDOWN_STARTED nil end |
#post_init ⇒ Object
327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 327 def post_init self.state = EAppState::EAS_POST_INIT self.state = EAppState::EAS_LOAD_INIT_DATA self.state = EAppState::EAS_INIT_PERIODICAL_TASKS self.state = EAppState::EAS_START_MANAGER_TASKS self.state = EAppState::EAS_START_REMOTE_SERVERS end |
#server_name ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/mrpin/core/app_info/app_info_base.rb', line 85 def server_name result = 'unknown' unless @config.nil? result = @config.server_name end result end |