Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Better error handling for capistrano deployment script #6

Merged
merged 1 commit into from

2 participants

Antti Pitkänen Ville Lautanala
Antti Pitkänen

Wrapped potentially error raising operations in capistrano notification script with begin-rescues so that a error in sending Flowdock notification would never cause failing of the entire deployment.

Ville Lautanala lautis merged commit 495009f into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 17, 2012
  1. Wrapped potentially error raising operations in capistrano notificati…

    Antti Pitkanen authored
    …on script with begin-rescues
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 10 deletions.
  1. +27 −10 lib/flowdock/capistrano.rb
37 lib/flowdock/capistrano.rb
View
@@ -12,24 +12,41 @@
end
task :save_deployed_branch do
- run "echo '#{source.head}' > #{current_path}/BRANCH"
+ begin
+ run "echo '#{source.head}' > #{current_path}/BRANCH"
+ rescue => e
+ puts "Flowdock: error in saving deployed branch information: " + e
+ end
end
task :set_flowdock_api do
set :rails_env, variables.include?(:stage) ? stage : ENV['RAILS_ENV']
- set :repo, Grit::Repo.new(".")
- config = Grit::Config.new(repo)
- set :flowdock_api, Flowdock::Flow.new(:api_token => flowdock_api_token,
- :source => "Capistrano deployment", :project => flowdock_project_name,
- :from => {:name => config["user.name"], :address => config["user.email"]})
+ begin
+ set :repo, Grit::Repo.new(".")
+ config = Grit::Config.new(repo)
+ rescue => e
+ puts "Flowdock: error in fetching your git repository information: " + e
+ end
+
+ begin
+ set :flowdock_api, Flowdock::Flow.new(:api_token => flowdock_api_token,
+ :source => "Capistrano deployment", :project => flowdock_project_name,
+ :from => {:name => config["user.name"], :address => config["user.email"]})
+ rescue => e
+ puts "Flowdock: error in configuring Flowdock API: " + e
+ end
end
task :notify_deploy_finished do
# send message to the flow
- flowdock_api.send_message(:format => "html",
- :subject => "#{flowdock_project_name} deployed with branch #{branch} on ##{rails_env}",
- :content => notification_message,
- :tags => ["deploy", "#{rails_env}"] | flowdock_deploy_tags)
+ begin
+ flowdock_api.send_message(:format => "html",
+ :subject => "#{flowdock_project_name} deployed with branch #{branch} on ##{rails_env}",
+ :content => notification_message,
+ :tags => ["deploy", "#{rails_env}"] | flowdock_deploy_tags)
+ rescue => e
+ puts "Flowdock: error in sending notification to your flow: " + e
+ end
end
def notification_message
Something went wrong with that request. Please try again.