<commit_before>after 'deploy:finishing', 'honeybadger:deploy'

namespace :honeybadger do
  desc 'Notify Honeybadger of the deployment.'
  # Run remotely so we use remote API keys, environment, etc.
  task :deploy => :env do
    on roles(:all, { :exclude => :no_release }) do |host|
      executable = RUBY_PLATFORM.downcase.include?('mswin') ? fetch(:rake, :'rake.bat') : fetch(:rake, :rake)
      rake_task  = fetch(:honeybadger_deploy_task, 'honeybadger:deploy')

      options = [rake_task]

      if fetch(:honeybadger_async_notify, false)
        ::SSHKit.config.command_map.prefix[:rake].push(:nohup)
        options << '>> /dev/null 2>&1 &'
      end

      info 'Notifying Honeybadger of Deploy.'

      within release_path do
        execute executable, options
      end

      info 'Honeybadger Notification Complete.'
    end
  end

  desc 'Setup ENV for Honeybadger deploy rake task.'
  task :env do
    on roles(:all, { :exclude => :no_release }) do |host|
      rails_env       = fetch(:rails_env, "production")
      honeybadger_env = fetch(:honeybadger_env, rails_env)
      repository      = fetch(:repo_url)
      local_user      = fetch(:honeybadger_user, ENV['USER'] || ENV['USERNAME'])
      api_key         = fetch(:honeybadger_api_key, ENV['HONEYBADGER_API_KEY'] || ENV['API_KEY'])
      revision        = fetch(:current_revision) do
        within(repo_path) do
          capture("cd #{repo_path} && git rev-parse --short HEAD")
        end
      end

      env = ["RAILS_ENV=#{rails_env}", "TO=#{honeybadger_env}", "REVISION=#{revision}", "REPO=#{repository}", "USER=#{local_user}"]
      env << "API_KEY=#{api_key}" if api_key
      ::SSHKit.config.command_map.prefix[:rake].unshift(*env)
    end
  end
end<commit_msg>Run capistrano3 task on primary server only.<commit_after>after 'deploy:finishing', 'honeybadger:deploy'

namespace :honeybadger do
  desc 'Notify Honeybadger of the deployment.'
  task :deploy do
    run_locally do
      info 'Notifying Honeybadger of deploy.'
    end

    invoke :'honeybadger:env'

    if server = fetch(:honeybadger_server)
      on server do |host|
        executable = RUBY_PLATFORM.downcase.include?('mswin') ? fetch(:rake, :'rake.bat') : fetch(:rake, :rake)
        rake_task  = fetch(:honeybadger_deploy_task, 'honeybadger:deploy')

        options = [rake_task]

        if fetch(:honeybadger_async_notify, false)
          ::SSHKit.config.command_map.prefix[:rake].push(:nohup)
          options << '>> /dev/null 2>&1 &'
        end

        within release_path do
          execute executable, options
        end

        info 'Honeybadger notification complete.'
      end
    else
      run_locally do
        error 'Honeybadger notification failed: primary server not found.'
      end
    end
  end

  desc 'Setup ENV for Honeybadger deploy rake task.'
  task :env do
    server = fetch(:honeybadger_server) do
      s = primary(:app)
      set(:honeybadger_server, s.select?({ :exclude => :no_release }) ? s : nil)
    end

    if server
      on server do |host|
        rails_env       = fetch(:rails_env, "production")
        honeybadger_env = fetch(:honeybadger_env, rails_env)
        repository      = fetch(:repo_url)
        local_user      = fetch(:honeybadger_user, ENV['USER'] || ENV['USERNAME'])
        api_key         = fetch(:honeybadger_api_key, ENV['HONEYBADGER_API_KEY'] || ENV['API_KEY'])
        revision        = fetch(:current_revision) do
          within(repo_path) do
            capture("cd #{repo_path} && git rev-parse --short HEAD")
          end
        end

        env = ["RAILS_ENV=#{rails_env}", "TO=#{honeybadger_env}", "REVISION=#{revision}", "REPO=#{repository}", "USER=#{local_user}"]
        env << "API_KEY=#{api_key}" if api_key
        ::SSHKit.config.command_map.prefix[:rake].unshift(*env)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12701717855283706, 'fraction_numerical': 0.0013014055179593961, 'mean_word_length': 2.9334698055271238, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4723381', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1237, 'n_words': 284}