Class: Metrux::Commands::Timer

Inherits:
Base
  • Object
show all
Defined in:
lib/metrux/commands/timer.rb

Constant Summary collapse

TIMER_MEASUREMENT_PREFIX_KEY =
'timers/'.freeze

Constants inherited from Base

Base::DEFAULT_TAGS

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Metrux::Commands::Base

Instance Method Details

#execute(key, params = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/metrux/commands/timer.rb', line 6

def execute(key, params = {})
  key = "#{TIMER_MEASUREMENT_PREFIX_KEY}#{key}"

  result, duration = if block_given?
                       calculate_duration { yield }
                     else
                       [nil, params.fetch(:duration)]
                     end

  write(key, format_data(duration, params), format_write_options(params))

  result
end