Class: D13n::Metric::Instrumentation::Conductor::Performance

Inherits:
Object
  • Object
show all
Defined in:
lib/d13n/metric/conductor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePerformance

Returns a new instance of Performance.



61
62
63
64
65
# File 'lib/d13n/metric/conductor.rb', line 61

def initialize
  @dependences = []
  @performances = []
  @name = nil
end

Instance Attribute Details

#dependencesObject (readonly)

Returns the value of attribute dependences.



59
60
61
# File 'lib/d13n/metric/conductor.rb', line 59

def dependences
  @dependences
end

#nameObject

Returns the value of attribute name.



53
54
55
# File 'lib/d13n/metric/conductor.rb', line 53

def name
  @name
end

#performedObject (readonly)

Returns the value of attribute performed.



52
53
54
# File 'lib/d13n/metric/conductor.rb', line 52

def performed
  @performed
end

Instance Method Details

#allowed_by_config?Boolean

Returns:

  • (Boolean)


101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/d13n/metric/conductor.rb', line 101

def allowed_by_config?
  return true if self.name.nil?

  key = "instrumentation.#{self.name}.disable".to_sym

  if (D13n.config[key] == true)
    D13n.logger.debug("Not setting up #{self.name} instrumentation for configuration #{key}")
    false
  else
    true
  end
end

#check_dependencesObject



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/d13n/metric/conductor.rb', line 88

def check_dependences
  return false unless allowed_by_config? && dependences

  dependences.all? do |score|
    begin
      score.call
    rescue => e
      D13n.logger.error("Error while checking #{self.name}:", e)
      false
    end
  end
end

#depend_onObject



84
85
86
# File 'lib/d13n/metric/conductor.rb', line 84

def depend_on
  @dependences << Proc.new
end

#named(new_name) ⇒ Object



114
115
116
# File 'lib/d13n/metric/conductor.rb', line 114

def named(new_name)
  self.name = new_name
end

#performObject



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/d13n/metric/conductor.rb', line 71

def perform
  @performances.each do |p|
    begin
      p.call
    rescue => e
      D13n.logger.error("Error while setting up #{self.name} instrumentation:", e)
      break
    end
  end
ensure
  perform!
end

#perform!Object



55
56
57
# File 'lib/d13n/metric/conductor.rb', line 55

def perform!
  @performed = true
end

#performancesObject



118
119
120
# File 'lib/d13n/metric/conductor.rb', line 118

def performances
  @performances << Proc.new
end

#ready?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/d13n/metric/conductor.rb', line 67

def ready?
  !performed and check_dependences
end