Class: Metriks::Reporter::ProcTitle
- Inherits:
-
Object
- Object
- Metriks::Reporter::ProcTitle
- Defined in:
- lib/metriks/reporter/proc_title.rb
Instance Method Summary collapse
- #add(name, suffix = nil, &block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(options = {}) ⇒ ProcTitle
constructor
A new instance of ProcTitle.
- #restart ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ ProcTitle
Returns a new instance of ProcTitle.
3 4 5 6 7 8 9 10 11 |
# File 'lib/metriks/reporter/proc_title.rb', line 3 def initialize( = {}) @rounding = [:rounding] || 1 @prefix = [:prefix] || $0.dup @interval = [:interval] || 5 @on_error = [:on_error] || proc { |ex| } @metrics = [] end |
Instance Method Details
#add(name, suffix = nil, &block) ⇒ Object
13 14 15 |
# File 'lib/metriks/reporter/proc_title.rb', line 13 def add(name, suffix = nil, &block) @metrics << [ name, suffix, block ] end |
#empty? ⇒ Boolean
17 18 19 |
# File 'lib/metriks/reporter/proc_title.rb', line 17 def empty? @metrics.empty? end |
#restart ⇒ Object
44 45 46 47 |
# File 'lib/metriks/reporter/proc_title.rb', line 44 def restart stop start end |
#start ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/metriks/reporter/proc_title.rb', line 21 def start @thread ||= Thread.new do loop do begin unless @metrics.empty? title = generate_title if title && !title.empty? $0 = "#{@prefix} #{title}" end end rescue Exception => ex @on_error[ex] rescue nil end sleep @interval end end end |
#stop ⇒ Object
39 40 41 42 |
# File 'lib/metriks/reporter/proc_title.rb', line 39 def stop @thread.kill if @thread @thread = nil end |