Sha256: 67a2aaf9af20f27352e57d645d1587c8d23922041b55ffd8c862565916d8112c

Contents?: true

Size: 1.68 KB

Versions: 15

Compression:

Stored size: 1.68 KB

Contents

require 'capistrano'
require 'instrumental_agent'
require 'etc'

if Capistrano::Configuration.instance
  Capistrano::Configuration.instance.load do
    namespace :instrumental do
      namespace :util do
        desc "marker for beginning of deploy"
        task :deploy_start do
          set :instrumental_deploy_start, Time.now
        end

        desc "marker for end of deploy"
        task :deploy_end do
          set :instrumental_deploy_end, Time.now
        end
      end

      desc "send a notice to instrumental about the deploy"
      task :record_deploy_notice do
        start_at = exists?(:instrumental_deploy_start) ? instrumental_deploy_start : Time.now
        end_at = exists?(:instrumental_deploy_end) ? instrumental_deploy_end : start_at
        deploy_duration_in_seconds = end_at - start_at
        deployer = Etc.getlogin.chomp
        agent_options = { :synchronous => true }
        agent_options[:collector] = instrumental_host if exists?(:instrumental_host)
        agent = Instrumental::Agent.new(instrumental_key, agent_options)
        message = if exists?(:deploy_message)
          deploy_message
        else
          "#{deployer} deployed #{current_revision}"
        end
        agent.notice(message,
                     start_at,
                     deploy_duration_in_seconds)
        logger.info("Notified Instrumental of deployment")
      end
    end

    before "deploy", "instrumental:util:deploy_start"
    after  "deploy", "instrumental:util:deploy_end"
    before "deploy:migrations", "instrumental:util:deploy_start"
    after  "deploy:migrations", "instrumental:util:deploy_end"
    after  "instrumental:util:deploy_end", "instrumental:record_deploy_notice"
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
instrumental_agent-2.0.0 lib/instrumental/capistrano.rb
instrumental_agent-2.0.0.alpha lib/instrumental/capistrano.rb
instrumental_agent-1.0.1 lib/instrumental/capistrano.rb
instrumental_agent-1.0.0 lib/instrumental/capistrano.rb
instrumental_agent-0.13.4 lib/instrumental/capistrano.rb
instrumental_agent-0.13.3 lib/instrumental/capistrano.rb
instrumental_agent-0.13.2 lib/instrumental/capistrano.rb
instrumental_agent-0.13.1 lib/instrumental/capistrano.rb
instrumental_agent-0.13.0 lib/instrumental/capistrano.rb
instrumental_agent-0.12.7 lib/instrumental/capistrano.rb
instrumental_agent-0.12.6 lib/instrumental/capistrano.rb
instrumental_agent-0.12.5 lib/instrumental/capistrano.rb
instrumental_agent-0.12.4 lib/instrumental/capistrano.rb
instrumental_agent-0.12.3 lib/instrumental/capistrano.rb
instrumental_agent-0.12.2 lib/instrumental/capistrano.rb