Sha256: ddce8ef491640682be251b3cf879c9b8f977bb31aa6543806d700ad70fe410e2

Contents?: true

Size: 1.14 KB

Versions: 6

Compression:

Stored size: 1.14 KB

Contents

module PlainApm
  ##
  # Tracks current revision of the app.
  #
  # This enables per-deploy metrics segmentation and checking
  # for performance regressions.
  module Hooks
    class Deploy
      ##
      # Collect once, immediately on install.
      def install
        collect
      end

      def collect
        result = git_revision || hg_revision || return

        tool, revision = *result

        Agent.instance.collect(
          {
            "source" => tool,
            "revision" => revision,
            "name" => "deploy",
            "started_at" => Time.now.to_f,
            "finished_at" => Time.now.to_f
          }
        )
      end

      private

      # TODO: other deploy mechanisms
      #
      # Also, we might not be in the app root.
      def git_revision
        return nil unless File.exist?(".git")

        ["git", `git rev-parse --short HEAD`.strip]
      rescue Error::ENOENT # No git installed
        nil
      end

      def hg_revision
        return nil unless File.exist?(".hg")

        ["hg", `hg log -l 1 -r . -T '{node}'`]
      rescue Error::ENOENT # No mercurial installed
        nil
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
plain_apm-0.5.4 lib/plain_apm/hooks/deploy.rb
plain_apm-0.5.3 lib/plain_apm/hooks/deploy.rb
plain_apm-0.5.2 lib/plain_apm/hooks/deploy.rb
plain_apm-0.5.1 lib/plain_apm/hooks/deploy.rb
plain_apm-0.5.0 lib/plain_apm/hooks/deploy.rb
plain_apm-0.4.0 lib/plain_apm/hooks/deploy.rb