Class: Excepty::Manager

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

Constant Summary collapse

EXCEPTY_SESSION_FILE_NAME =
"tmp/excepty.sid"
EXCEPTY_LOGGER_FILE_NAME =
"excepty.log"
EXCEPTY_DEFAULT_LOG_LEVEL =
Logger::INFO
@@excepty_session_id =
nil

Class Method Summary collapse

Class Method Details

.analyse_exception(env, exception) ⇒ Object



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
# File 'lib/excepty/manager.rb', line 61

def self.analyse_exception( env, exception )
  logga "Excepty - Exception detected"
  app_env = get_env_struct( env )
  gem_info = get_gem_info_struct()
  exc_info = get_exception_struct( exception, env )
  struct_to_send = { app_env: app_env, gem_info: gem_info, exc_info: exc_info }
  begin struct_to_send["time_now"] = Time.now.utc; rescue Exception => e; end
  #@@excepty_session_id = nil
  if @@excepty_session_id.blank?
    logga "allora @@excepty_session_id.blank" if EXCEPTY_IN_TESTING_MODE
    #self.start()
    file = File.new( EXCEPTY_SESSION_FILE_NAME, "r" )
    if file
       content = file.sysread(20)
       logga content if EXCEPTY_IN_TESTING_MODE
       logga "LEGGGGGOOOOO"
       logga "LEGGGGGOOOOO"
       logga "LEGGGGGOOOOO"
       @@excepty_session_id = content.to_i
     end
  end
  logga "@@excepty_session_id: #{@@excepty_session_id}" if EXCEPTY_IN_TESTING_MODE
  logga "self.excepty_session_id: #{ self.excepty_session_id }" if EXCEPTY_IN_TESTING_MODE
  begin
    logga "@@@@excepty_session_id_bis: #{ @@excepty_session_id_bis }" if EXCEPTY_IN_TESTING_MODE
  rescue Exception => e
  end
  begin
    returned_obj = Excepty::Connector.call( "/collector/error", struct_to_send, { session_id: ( @@excepty_session_id || self.excepty_session_id ) } )
    logga "Excepty - Exception sent"
  rescue Exception => e
    logga "Excepty - Exception NOT sent"
  end
end

.excepty_session_idObject



96
97
98
# File 'lib/excepty/manager.rb', line 96

def self.excepty_session_id
  @@excepty_session_id
end

.logga(text, level = EXCEPTY_DEFAULT_LOG_LEVEL) ⇒ Object



100
101
102
103
# File 'lib/excepty/manager.rb', line 100

def self.logga(text, level = EXCEPTY_DEFAULT_LOG_LEVEL)
  text = "[Excepty(#{name})] #{text}"
  logger.add level, "#{Time.now.strftime('%FT%T%z')}: #{text}" if logger
end

.startObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/excepty/manager.rb', line 24

def self.start()
  self.logger ||= Logger.new( File.join( Rails.root, "log", EXCEPTY_LOGGER_FILE_NAME ) )
  
  logga( "Manager: - start" ) if EXCEPTY_IN_TESTING_MODE
  
  app_env = get_env_struct()
  gem_info = get_gem_info_struct()
  app_info = get_app_info_struct()
  
  struct_to_send = { app_env: app_env, gem_info: gem_info, app_info: app_info }
  begin struct_to_send["time_now"] = Time.now.utc; rescue Exception => e; end
  #struct_to_send = {}
  returned_obj = Excepty::Connector.call( "/collector/start", struct_to_send )
  if returned_obj['status'].to_i == 200
    @@excepty_session_id = returned_obj['data']['reload_id']
    @@excepty_session_id_bis = @@excepty_session_id
    File.delete( EXCEPTY_SESSION_FILE_NAME ) if File::exists?( "file.rb" )
    file = File.new( EXCEPTY_SESSION_FILE_NAME, "w" )
    file.puts @@excepty_session_id
    file.close
    logga "Dir.tmpdir: #{ Dir.tmpdir }" if EXCEPTY_IN_TESTING_MODE
    message_response = "Excepty - connetted"
    logga "@@excepty_session_id: #{@@excepty_session_id}" if EXCEPTY_IN_TESTING_MODE
    logga "self.excepty_session_id: #{ self.excepty_session_id }" if EXCEPTY_IN_TESTING_MODE
  else
    #TODO vedere che fare
    message_response = "Excepty - NOT connetted"
  end
  begin
    logga(message_response)
    Rails.logger.info(message_response)
  rescue Exception => e
  end
  logga "@@excepty_session_id: #{@@excepty_session_id}" if EXCEPTY_IN_TESTING_MODE
  logga "self.excepty_session_id: #{ self.excepty_session_id }" if EXCEPTY_IN_TESTING_MODE
end