Class: Traker::Instrumenter
- Inherits:
-
Object
- Object
- Traker::Instrumenter
- Defined in:
- lib/traker/instrumenter.rb
Overview
Wraps array of rake tasks, and auguments each one of them with Traker features
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#tasks ⇒ Object
Returns the value of attribute tasks.
Instance Method Summary collapse
-
#initialize(tasks) ⇒ Instrumenter
constructor
A new instance of Instrumenter.
- #instrument ⇒ Object
Constructor Details
#initialize(tasks) ⇒ Instrumenter
Returns a new instance of Instrumenter.
9 10 11 12 |
# File 'lib/traker/instrumenter.rb', line 9 def initialize(tasks) @tasks = tasks @config = Traker::Config.load end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/traker/instrumenter.rb', line 7 def config @config end |
#tasks ⇒ Object
Returns the value of attribute tasks.
7 8 9 |
# File 'lib/traker/instrumenter.rb', line 7 def tasks @tasks end |
Instance Method Details
#instrument ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/traker/instrumenter.rb', line 14 def instrument tasks.each do |t| task_name = t.name next unless tasks_to_be_run.map { |task| task['name'] }.include?(task_name) handler = proc do |&block| record = Traker::Task.find_or_initialize_by(name: task_name, environment: config.env) record.started_at = DateTime.now record.is_success = true begin block.call record.run_count += 1 rescue StandardError => e record.is_success = false record.error = e.backtrace.first raise e ensure record.finished_at = DateTime.now record.save! end end yield task_name, handler end end |