Sha256: df0c51992e63981d43cbb2e08d3cfba739be72c1aec9f53d791fd562ea6997f8

Contents?: true

Size: 1.48 KB

Versions: 10

Compression:

Stored size: 1.48 KB

Contents

require 'net/http'
require 'rubygems'
require 'json'

namespace :rollbar do

  desc 'Send the deployment notification to Rollbar.'
  task :deploy do
    on roles fetch(:rollbar_role) do
      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.)") if Capistrano::VERSION =~ /^3\.0/

      uri    = URI.parse 'https://api.rollbar.com/api/1/deploy/'
      params = {
        :local_username => fetch(:rollbar_user),
        :access_token   => fetch(:rollbar_token),
        :environment    => fetch(:rollbar_env),
        :revision       => fetch(:rollbar_revision) }

      debug "Building Rollbar POST to #{uri} with #{params.inspect}"

      request      = Net::HTTP::Post.new(uri.request_uri)
      request.body = ::JSON.dump(params)

      Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
        http.request(request)
      end

      info 'Rollbar notification complete.'
    end
  end
end

namespace :deploy do
  after 'deploy:finished', 'rollbar:deploy'
end

namespace :load do
  task :defaults do
    set :rollbar_user,      Proc.new { ENV['USER'] || ENV['USERNAME'] }
    set :rollbar_env,       Proc.new { fetch :rails_env, 'production' }
    set :rollbar_token,     Proc.new { abort "Please specify the Rollbar access token, set :rollbar_token, 'your token'" }
    set :rollbar_role,      Proc.new { :app }
    set :rollbar_revision,  Proc.new { fetch :current_revision }
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rollbar-2.7.1 lib/rollbar/tasks/rollbar.cap
rollbar-2.7.0 lib/rollbar/tasks/rollbar.cap
rollbar-2.6.3 lib/rollbar/tasks/rollbar.cap
rollbar-2.6.2 lib/rollbar/tasks/rollbar.cap
rollbar-2.6.1 lib/rollbar/tasks/rollbar.cap
rollbar-2.6.0 lib/rollbar/tasks/rollbar.cap
rollbar-2.5.2 lib/rollbar/tasks/rollbar.cap
rollbar-2.5.1 lib/rollbar/tasks/rollbar.cap
rollbar-2.5.0 lib/rollbar/tasks/rollbar.cap
rollbar-2.4.0 lib/rollbar/tasks/rollbar.cap