Class: Mutx::Workers::ConnectivityCheck

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker, Sidetiq::Schedulable
Defined in:
lib/mutx/background_jobs/workers/connectivity_check.rb

Instance Method Summary collapse

Instance Method Details

#performObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mutx/background_jobs/workers/connectivity_check.rb', line 13

def perform
#def self.check
  #Mutx::Database::MongoConnector.new Mutx::Support::Configuration.db_connection_data
  path = "#{Dir.pwd}/mutx/temp/connectivity_check.txt"
  message_lost = "Internet connection lost!"
  begin
    if open("http://www.google.com/")
      puts "HAY INTERNET..."
      contents = File.read("#{path}") if File.file?("#{path}")
      Mutx::Support::MailSender.new.sender(nil, "No internet connection for a while, now is ready again", "[email protected]", "Prueba", nil, nil, nil, nil, nil) if ( (!contents.nil?) && (contents.include? "#{message_lost}") )
      File.delete("#{path}") if File.file?("#{path}")
    else
      raise StandardError.new "#{message_lost}"
    end
  rescue StandardError => e
    output = File.open("#{path}", "a+")
    text = "#{Time.now} - #{e.message}"
    output.puts "#{text}"
    output.close
  end
end