<commit_before>require 'whenever/capistrano/support'

Capistrano::Configuration.instance(:must_exist).load do
  Whenever::CapistranoSupport.load_into(self)

  _cset(:whenever_roles)        { :db }
  _cset(:whenever_options)      { {:roles => fetch(:whenever_roles)} }
  _cset(:whenever_command)      { "whenever" }
  _cset(:whenever_identifier)   { fetch :application }
  _cset(:whenever_environment)  { fetch :rails_env, "production" }
  _cset(:whenever_variables)    { "environment=#{fetch :whenever_environment}" }
  _cset(:whenever_update_flags) { "--update-crontab #{fetch :whenever_identifier} --set #{fetch :whenever_variables}" }
  _cset(:whenever_clear_flags)  { "--clear-crontab #{fetch :whenever_identifier}" }

  namespace :whenever do
    desc "Update application's crontab entries using Whenever"
    task :update_crontab do
      args = {
        :command => fetch(:whenever_command),
        :flags   => fetch(:whenever_update_flags),
        :path    => fetch(:latest_release)
      }

      if whenever_servers.any?
        whenever_run_commands(args)

        on_rollback do
          if fetch(:previous_release)
            # rollback to the previous release's crontab
            args[:path] = fetch(:previous_release)
          else
            # clear the crontab if no previous release
            args[:path]  = fetch(:release_path)
            args[:flags] = fetch(:whenever_clear_flags)
          end

          whenever_run_commands(args)
        end
      end
    end

    desc "Clear application's crontab entries using Whenever"
    task :clear_crontab do
      if whenever_servers.any?
        args = {
          :command => fetch(:whenever_command),
          :flags   => fetch(:whenever_clear_flags),
          :path    => fetch(:latest_release)
        }

        whenever_run_commands(args)
      end
    end
  end
end<commit_msg>Makes sure capistrano cd's to the right directory when executing a deploy:rollback<commit_after>require 'whenever/capistrano/support'

Capistrano::Configuration.instance(:must_exist).load do
  Whenever::CapistranoSupport.load_into(self)

  _cset(:whenever_roles)        { :db }
  _cset(:whenever_options)      { {:roles => fetch(:whenever_roles)} }
  _cset(:whenever_command)      { "whenever" }
  _cset(:whenever_identifier)   { fetch :application }
  _cset(:whenever_environment)  { fetch :rails_env, "production" }
  _cset(:whenever_variables)    { "environment=#{fetch :whenever_environment}" }
  _cset(:whenever_update_flags) { "--update-crontab #{fetch :whenever_identifier} --set #{fetch :whenever_variables}" }
  _cset(:whenever_clear_flags)  { "--clear-crontab #{fetch :whenever_identifier}" }

  namespace :whenever do
    desc "Update application's crontab entries using Whenever"
    task :update_crontab do
      args = {
        :command => fetch(:whenever_command),
        :flags   => fetch(:whenever_update_flags),
        :path    => fetch(:latest_release)
      }

      if whenever_servers.any?
        if task_call_frames[0].task.fully_qualified_name == 'deploy:rollback'
          if fetch(:previous_release)
            # rollback to the previous release's crontab
            args[:path] = fetch(:previous_release)
          else
            # clear the crontab if no previous release
            args[:path]  = fetch(:release_path)
            args[:flags] = fetch(:whenever_clear_flags)
          end
        end

        whenever_run_commands(args)

        on_rollback do
          if fetch(:previous_release)
            # rollback to the previous release's crontab
            args[:path] = fetch(:previous_release)
          else
            # clear the crontab if no previous release
            args[:path]  = fetch(:release_path)
            args[:flags] = fetch(:whenever_clear_flags)
          end

          whenever_run_commands(args)
        end
      end
    end

    desc "Clear application's crontab entries using Whenever"
    task :clear_crontab do
      if whenever_servers.any?
        args = {
          :command => fetch(:whenever_command),
          :flags   => fetch(:whenever_clear_flags),
          :path    => fetch(:latest_release)
        }

        whenever_run_commands(args)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10269758637008992, 'fraction_numerical': 0.000236630383341221, 'mean_word_length': 2.764024933214604, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '6325387', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1242, 'n_words': 255}