class Traker::Instrumenter

Wraps array of rake tasks, and auguments each one of them with Traker features

Attributes

config[RW]
tasks[RW]

Public Class Methods

new(tasks) click to toggle source
# File lib/traker/instrumenter.rb, line 9
def initialize(tasks)
  @tasks = tasks
  @config = Traker::Config.load
end

Public Instance Methods

instrument() { |task_name, handler| ... } click to toggle source
# 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

Private Instance Methods

tasks_to_be_run() click to toggle source
# File lib/traker/instrumenter.rb, line 45
def tasks_to_be_run
  config.tasks
end