LoginSignup
9
5

More than 5 years have passed since last update.

Rakeの終了時に実行したtaskの成否の通知を送る方法

Posted at

at_exitを使うと終了時に処理を実行できる。
通知を送る処理をat_exitで登録するRakeタスクを定義し成否を通知したいタスクの依存タスクに追加するとべんり。

Rakefile
desc "notify the tasks finished successfully or not"
task :notify_tasks_finished do
  at_exit do
    tasks = Rake.application.top_level_tasks.join(", ")
    if $!.nil? || $!&.success?
      puts "success: #{tasks}"
    else
      puts "fail: #{tasks}"
    end
  end
end

desc "hey"
task hey: :notify_tasks_finished do
  puts "hey"
end


desc "yo"
task yo: :notify_tasks_finished do
  yo
end
% rake hey
hey
success: hey
% rake yo
rake aborted!
NameError: undefined local variable or method `yo' for main:Object
/home/sei/tmp/rake.rb:22:in `block in <top (required)>'
Tasks: TOP => yo
(See full trace by running task with --trace)
fail: yo
9
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
5