module Rollbar::CapistranoTasks
Module containing the logic of Capistrano tasks for deploy tracking
Public Class Methods
Source
# File lib/rollbar/capistrano_tasks.rb, line 38 def deploy_failed(capistrano, logger, dry_run) deploy_update(capistrano, logger, dry_run, :desc => 'Setting deployment status to `failed` in Rollbar') do report_deploy_failed(capistrano, dry_run) end end
Source
# File lib/rollbar/capistrano_tasks.rb, line 7 def deploy_started(capistrano, logger, dry_run) deploy_task(logger, :desc => 'Notifying Rollbar of deployment start') do result = report_deploy_started(capistrano, dry_run) debug_request_response(logger, result) capistrano.set(:rollbar_deploy_id, 123) if dry_run skip_in_dry_run(logger, dry_run) do if result[:success] && (deploy_id = result[:data] && result[:data][:deploy_id]) capistrano.set :rollbar_deploy_id, deploy_id else message = format_message('Unable to report deploy to Rollbar', result[:message]) log_error(logger, message) end end end end
Source
# File lib/rollbar/capistrano_tasks.rb, line 29 def deploy_succeeded(capistrano, logger, dry_run) deploy_update( capistrano, logger, dry_run, :desc => 'Setting deployment status to `succeeded` in Rollbar' ) do report_deploy_succeeded(capistrano, dry_run) end end
Private Class Methods
Source
# File lib/rollbar/capistrano_tasks.rb, line 75 def capistrano_300_warning(logger) unless ::Capistrano.const_defined?('VERSION') && ::Capistrano::VERSION =~ /^3\.0/ return end logger.warn('You need to upgrade capistrano to >= 3.1 version in order'\ 'to correctly report deploys to Rollbar. (On 3.0, the reported revision'\ 'will be incorrect.)') end
Source
# File lib/rollbar/capistrano_tasks.rb, line 144 def debug_request_response(logger, result) # NOTE: in Capistrano debug messages go to log/capistrano.log but not to # stdout even if log_level == :debug logger.debug result[:request_info] logger.debug result[:response_info] if result[:response_info] end
Source
# File lib/rollbar/capistrano_tasks.rb, line 127 def depend_on_deploy_id(capistrano, logger) if capistrano.fetch(:rollbar_deploy_id) yield else log_error logger, 'Failed to update the deploy in Rollbar. No deploy id available.' end end
Source
# File lib/rollbar/capistrano_tasks.rb, line 47 def deploy_task(logger, opts = {}) capistrano_300_warning(logger) logger.info opts[:desc] if opts[:desc] yield rescue StandardError => e log_error logger, "Error reporting to Rollbar: #{e.inspect}" end
Source
# File lib/rollbar/capistrano_tasks.rb, line 55 def deploy_update(capistrano, logger, dry_run, opts = {}) deploy_task(logger, opts) do depend_on_deploy_id(capistrano, logger) do result = yield debug_request_response(logger, result) skip_in_dry_run(logger, dry_run) do if result[:success] logger.info 'Updated deploy status in Rollbar' else message = format_message('Unable to update deploy status in Rollbar', result[:message]) log_error(logger, message) end end end end end
Source
# File lib/rollbar/capistrano_tasks.rb, line 151 def format_message(*args) args.compact.join(': ') end
Source
# File lib/rollbar/capistrano_tasks.rb, line 155 def log_error(logger, message) # Capistrano 2.x doesn't have the #error method, # so we use #important if #error isn't present if logger.respond_to?(:error) logger.error message elsif logger.respond_to?(:important) logger.important message end end
Source
# File lib/rollbar/capistrano_tasks.rb, line 114 def report_deploy_failed(capistrano, dry_run) ::Rollbar::Deploy.update( { :comment => capistrano.fetch(:rollbar_comment), :proxy => :ENV, :dry_run => dry_run }, capistrano.fetch(:rollbar_token), capistrano.fetch(:rollbar_deploy_id), :failed ) end
Source
# File lib/rollbar/capistrano_tasks.rb, line 85 def report_deploy_started(capistrano, dry_run) ::Rollbar::Deploy.report( { :rollbar_username => capistrano.fetch(:rollbar_user), :local_username => capistrano.fetch(:rollbar_user), :comment => capistrano.fetch(:rollbar_comment), :status => :started, :proxy => :ENV, :dry_run => dry_run }, capistrano.fetch(:rollbar_token), capistrano.fetch(:rollbar_env), capistrano.fetch(:rollbar_revision) ) end
Source
# File lib/rollbar/capistrano_tasks.rb, line 101 def report_deploy_succeeded(capistrano, dry_run) ::Rollbar::Deploy.update( { :comment => capistrano.fetch(:rollbar_comment), :proxy => :ENV, :dry_run => dry_run }, capistrano.fetch(:rollbar_token), capistrano.fetch(:rollbar_deploy_id), :succeeded ) end
Source
# File lib/rollbar/capistrano_tasks.rb, line 136 def skip_in_dry_run(logger, dry_run) if dry_run logger.info 'Skipping sending HTTP requests to Rollbar in dry run.' else yield end end