Skip to content

Instantly share code, notes, and snippets.

@joshuaflanagan
Created April 3, 2011 23:04
Show Gist options
  • Save joshuaflanagan/900909 to your computer and use it in GitHub Desktop.
Save joshuaflanagan/900909 to your computer and use it in GitHub Desktop.
Include this from your rakefile to get a (Windows) growl notification when rake process completes
unless ENV["BUILD_NUMBER"] # do not use growl when running on the CI server
task :growl do
Rake::Application.growl
end
module Rake
class Application
# override task execution so that growl task is always called last
alias :raw_top_level :top_level
def top_level
followed_by :growl do
raw_top_level
end
end
def self.growl(err_message=nil)
message = err_message || "Rake complete"
growl_type = err_message.nil? ? "Complete" : "Fail"
priority = err_message.nil? ? 0 : 1
icon = err_message.nil? ? "dt-logo-60.png" : "icon-unread.png"
RakeFileUtils::verbose(false) do
sh "tools/growl/growlnotify.exe /r:\"Complete\",\"Fail\" /a:\"rake\" /t:\"rake\" \"#{message}\" /n:\"#{growl_type}\" /p:#{priority} /i:\"../../source/DovetailCRM.Web/Content/images/#{icon}"
end
end
# override exception handling to send a growl notification
def standard_exception_handling
begin
yield
rescue SystemExit => ex
# Exit silently with current status
raise
rescue OptionParser::InvalidOption => ex
# Exit silently
exit(false)
rescue Exception => ex
# Exit with error message
$stderr.puts "#{name} aborted!"
$stderr.puts ex.message
if options.trace
$stderr.puts ex.backtrace.join("\n")
else
$stderr.puts ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || ""
$stderr.puts "(See full trace by running task with --trace)"
end
Application.growl ex.message
exit(false)
end
end
def followed_by(*extra_tasks)
orig_task = top_level_tasks.dup
@top_level_tasks = top_level_tasks + extra_tasks
yield
@top_level_tasks = orig_task
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment