Class: HotCatch::MakeHttpsRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/hot_catch.rb

Overview

Отвечает за отправку логов на главное приложение

Instance Method Summary collapse

Constructor Details

#initialize(url = nil, try_count = 0) ⇒ MakeHttpsRequest

Returns a new instance of MakeHttpsRequest.



30
31
32
33
34
35
36
37
# File 'lib/hot_catch.rb', line 30

def initialize(url = nil, try_count = 0)
  @try_count = try_count
  @url = url
  unless @url
    File.open("config/hot_catch_config.json"){ |file| @url = JSON.parse(file.read)["url"] }
    @url += "/main_hot_catch_logs"
  end
end

Instance Method Details

#nginx_g_log(log_data) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/hot_catch.rb', line 51

def nginx_g_log(log_data)
  body_log = {main_hot_catch_log:
    {
      "log_data":log_data,
      "name_app":Rails.application.class.parent_name,
      "from_log":"Nginx"
    }
  }
  HardWorker.perform_async(body_log, @url, @try_count)
end

#rails_g_log(log_data, status) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/hot_catch.rb', line 39

def rails_g_log(log_data, status)
  body_log = {main_hot_catch_log:
    {
      "log_data":log_data,
      "name_app":Rails.application.class.parent_name,
      "from_log":"Rails",
      "status":status
    }
  }
  HardWorker.perform_async(body_log, @url, @try_count)
end

#send_log(body_log) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/hot_catch.rb', line 73

def send_log(body_log)
  response = call(@url, body_log)
  # если на запрос пришёл ответ, то пришло уведомление об ошибке, которое логируется
  # Кроме того данное сообщение помещается в очередь и отправляется через какое-то время
  unless response.to_s.empty?
    str = "\n" + (?-*20) + "\n#{Time.now}\nlogs:\n#{body_log.to_s}\nresponse\n:#{response}\n" + (?-*20) + "\n"
    File.open("log/hot_catch_log_response_errors", 'a'){ |file| file.write str.encode('UTF-8', {
      :invalid => :replace,
      :undef   => :replace,
      :replace => '?'
    }) }
  end
end

#system_g_log(log_data) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/hot_catch.rb', line 62

def system_g_log(log_data)
  body_log = {main_hot_catch_log:
    {
      "log_data":log_data,
      "name_app":Rails.application.class.parent_name,
      "from_log":"System"
    }
  }
  HardWorker.perform_async(body_log, @url, @try_count)
end