Module: RorVsWild

Defined in:
lib/rorvswild.rb,
lib/rorvswild/agent.rb,
lib/rorvswild/local.rb,
lib/rorvswild/queue.rb,
lib/rorvswild/client.rb,
lib/rorvswild/locator.rb,
lib/rorvswild/section.rb,
lib/rorvswild/version.rb,
lib/rorvswild/installer.rb,
lib/rorvswild/local/queue.rb,
lib/rorvswild/plugin/mongo.rb,
lib/rorvswild/plugin/redis.rb,
lib/rorvswild/rails_loader.rb,
lib/rorvswild/plugin/resque.rb,
lib/rorvswild/plugin/faktory.rb,
lib/rorvswild/plugin/sidekiq.rb,
lib/rorvswild/plugin/net_http.rb,
lib/rorvswild/local/middleware.rb,
lib/rorvswild/plugin/active_job.rb,
lib/rorvswild/plugin/middleware.rb,
lib/rorvswild/plugin/action_view.rb,
lib/rorvswild/plugin/delayed_job.rb,
lib/rorvswild/plugin/action_mailer.rb,
lib/rorvswild/plugin/active_record.rb,
lib/rorvswild/plugin/elasticsearch.rb,
lib/rorvswild/plugin/action_controller.rb

Defined Under Namespace

Modules: Local, Plugin Classes: Agent, Client, Installer, Locator, Queue, RailsLoader, Section

Constant Summary collapse

VERSION =
"1.5.12".freeze

Class Method Summary collapse

Class Method Details

.agentObject


18
19
20
# File 'lib/rorvswild.rb', line 18

def self.agent
  @agent
end

.catch_error(extra_details = nil, &block) ⇒ Object


34
35
36
# File 'lib/rorvswild.rb', line 34

def self.catch_error(extra_details = nil, &block)
  agent ? agent.catch_error(extra_details, &block) : block.call
end

.checkObject


58
59
60
61
62
63
64
65
66
# File 'lib/rorvswild.rb', line 58

def self.check
  api_key = RorVsWild.agent.config[:api_key]
  return puts "You API key is missing and has to be defined in config/rorvswild.yml." if !api_key || api_key.empty?
  puts case response = agent.client.post("/jobs", jobs: [{sections: [], name: "RorVsWild.check", runtime: 0}])
  when Net::HTTPOK then "Connection to RorVsWild works fine !"
  when Net::HTTPUnauthorized then "Wrong API key"
  else puts "Something went wrong: #{response.inspect}"
  end
end

.clock_millisecondsObject


54
55
56
# File 'lib/rorvswild.rb', line 54

def self.clock_milliseconds
  Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
end

.initialize_logger(destination = nil) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rorvswild.rb', line 42

def self.initialize_logger(destination = nil)
  if destination.respond_to?(:info) && destination.respond_to?(:warn) && destination.respond_to?(:error)
    destination
  elsif destination
    Logger.new(destination)
  elsif defined?(Rails)
    Rails.logger
  else
    Logger.new(STDOUT)
  end
end

.loggerObject


22
23
24
# File 'lib/rorvswild.rb', line 22

def self.logger
  @logger ||= initialize_logger
end

.measure_block(name, &block) ⇒ Object


30
31
32
# File 'lib/rorvswild.rb', line 30

def self.measure_block(name, &block)
  agent ? agent.measure_block(name , &block) : block.call
end

.measure_code(code) ⇒ Object


26
27
28
# File 'lib/rorvswild.rb', line 26

def self.measure_code(code)
  agent ? agent.measure_code(code) : eval(code)
end

.record_error(exception, extra_details = nil) ⇒ Object


38
39
40
# File 'lib/rorvswild.rb', line 38

def self.record_error(exception, extra_details = nil)
  agent.record_error(exception, extra_details) if agent
end

.start(config) ⇒ Object


10
11
12
13
14
15
16
# File 'lib/rorvswild.rb', line 10

def self.start(config)
  @logger = initialize_logger(config[:logger])
  @agent = Agent.new(config)
rescue Exception => ex
  logger.error(ex)
  raise
end