Class: Harvestdor::Indexer::Metrics
- Inherits:
-
Object
- Object
- Harvestdor::Indexer::Metrics
- Defined in:
- lib/harvestdor/indexer/metrics.rb
Overview
Harvest metrics tracker
Instance Attribute Summary collapse
-
#error_count ⇒ Object
Returns the value of attribute error_count.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#success_count ⇒ Object
Returns the value of attribute success_count.
Instance Method Summary collapse
-
#error! ⇒ Object
Record an error.
-
#initialize(options = {}) ⇒ Metrics
constructor
A new instance of Metrics.
-
#success! ⇒ Object
Record a successful run.
-
#tally(options = {}) ⇒ Object
Wrap an operation in tally block; if the block completes without throwing an exception, tally a success.
-
#total ⇒ Object
Total number of runs.
Constructor Details
#initialize(options = {}) ⇒ Metrics
Returns a new instance of Metrics.
7 8 9 10 11 |
# File 'lib/harvestdor/indexer/metrics.rb', line 7 def initialize( = {}) @success_count = 0 # the number of objects successfully indexed @error_count = 0 # the number of objects that failed @logger = [:logger] || Logger.new(STDERR) end |
Instance Attribute Details
#error_count ⇒ Object
Returns the value of attribute error_count.
5 6 7 |
# File 'lib/harvestdor/indexer/metrics.rb', line 5 def error_count @error_count end |
#logger ⇒ Object
Returns the value of attribute logger.
5 6 7 |
# File 'lib/harvestdor/indexer/metrics.rb', line 5 def logger @logger end |
#success_count ⇒ Object
Returns the value of attribute success_count.
5 6 7 |
# File 'lib/harvestdor/indexer/metrics.rb', line 5 def success_count @success_count end |
Instance Method Details
#error! ⇒ Object
Record an error
40 41 42 |
# File 'lib/harvestdor/indexer/metrics.rb', line 40 def error! @error_count += 1 end |
#success! ⇒ Object
Record a successful run
34 35 36 |
# File 'lib/harvestdor/indexer/metrics.rb', line 34 def success! @success_count += 1 end |
#tally(options = {}) ⇒ Object
Wrap an operation in tally block; if the block completes without throwing an exception, tally a success. If the block throws an exception, catch it and tally a failure.
Callers can provide an :on_error handler to receive the exception and process it appropriately.
23 24 25 26 27 28 29 30 |
# File 'lib/harvestdor/indexer/metrics.rb', line 23 def tally( = {}) yield success! rescue => e error! logger.error "Failed to process: #{e.}" [:on_error].call e if [:on_error] end |
#total ⇒ Object
Total number of runs
46 47 48 |
# File 'lib/harvestdor/indexer/metrics.rb', line 46 def total @success_count + @error_count end |