Last active
March 3, 2016 12:29
-
-
Save elandesign/fc11277e23587ecb1c72 to your computer and use it in GitHub Desktop.
Add some metrics to your Rakefiles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task :environment do | |
puts "environment" | |
end | |
namespace :metrics do | |
task :before do | |
# Get time task started | |
@started_at = Time.now.to_i | |
end | |
task :after, :name do |t, args| | |
# Do something with the time taken | |
puts "Task #{args[:name]} - took #{Time.now.to_i - @started_at}s" | |
end | |
end | |
namespace :foo do | |
task :bar => :environment do | |
puts "bar" | |
sleep(rand(5)) | |
end | |
task :quick => :environment do | |
puts "quick" | |
end | |
end | |
# Wrap each task in the foo namespace in with metrics before/after | |
Rake.application.tasks_in_scope(Rake::Scope.new(:foo)).each do |task| | |
task.enhance(["metrics:before"]) do | |
Rake::Task["metrics:after"].invoke(task.name) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment