<commit_before>require 'guard'
require 'guard/guard'

module Guard
  class Resque < Guard

    DEFAULT_SIGNAL = :QUIT
    DEFAULT_QUEUE = '*'.freeze
    DEFAULT_COUNT = 1
    DEFAULT_TASK_SINGLE = 'resque:work'.freeze
    DEFAULT_TASK_MULTIPLE = 'resque:workers'.freeze

    # Allowable options are:
    #  - :environment  e.g. 'test'
    #  - :task .e.g 'resque:work'
    #  - :queue e.g. '*'
    #  - :count e.g. 3
    #  - :verbose e.g. true
    #  - :vverbose e.g. true
    #  - :trace e.g. true
    #  - :stop_signal e.g. :QUIT or :SIGQUIT
    def initialize(watchers = [], options = {})
      @options = options
      @pid = nil
      @stop_signal = options[:stop_signal] || DEFAULT_SIGNAL
      @options[:queue] ||= DEFAULT_QUEUE
      @options[:count] ||= DEFAULT_COUNT
      @options[:task] ||= (@options[:count].to_i == 1) ? DEFAULT_TASK_SINGLE : DEFAULT_TASK_MULTIPLE
      super
    end

    def start
      stop
      UI.info 'Starting up resque...'
      UI.info [ cmd, env.map{|v| v.join('=')} ].join(' ')

      # launch Resque worker
      @pid = spawn(env, cmd)
    end

    def stop
      if @pid
        UI.info 'Stopping resque...'
        ::Process.kill @stop_signal, @pid
        begin
          Timeout.timeout(15) do
            ::Process.wait @pid
          end
        rescue Timeout::Error
          UI.info 'Sending SIGKILL to resque, as it\'s taking too long to shutdown.'
          ::Process.kill :KILL, @pid
          ::Process.wait @pid
        end
        UI.info 'Stopped process resque'
      end
    rescue Errno::ESRCH
      UI.info 'Guard::Resque lost the Resque worker subprocess!'
    ensure
      @pid = nil
    end

    # Called on Ctrl-Z signal
    def reload
      UI.info 'Restarting resque...'
      restart
    end

    # Called on Ctrl-/ signal
    def run_all
      true
    end

    # Called on file(s) modifications
    def run_on_change(paths)
      restart
    end

    def restart
      stop
      start
    end

    private

    def cmd
      command = ['bundle exec rake', @options[:task].to_s]

      # trace setting
      command << '--trace' if @options[:trace]

      return command.join(' ')
    end

    def env
      var = Hash.new

      var['QUEUE']     = @options[:queue].to_s       if @options[:queue]
      var['COUNT']     = @options[:count].to_s       if @options[:count]
      var['RAILS_ENV'] = @options[:environment].to_s if @options[:environment]

      var['VERBOSE']  = '1' if @options[:verbose]
      var['VVERBOSE'] = '1' if @options[:vverbose]

      return var
    end
  end
end<commit_msg>adding interval to options<commit_after>require 'guard'
require 'guard/guard'

module Guard
  class Resque < Guard

    DEFAULT_SIGNAL = :QUIT
    DEFAULT_QUEUE = '*'.freeze
    DEFAULT_COUNT = 1
    DEFAULT_TASK_SINGLE = 'resque:work'.freeze
    DEFAULT_TASK_MULTIPLE = 'resque:workers'.freeze

    # Allowable options are:
    #  - :environment  e.g. 'test'
    #  - :task .e.g 'resque:work'
    #  - :queue e.g. '*'
    #  - :count e.g. 3
    #  - :interval e.g. 5
    #  - :verbose e.g. true
    #  - :vverbose e.g. true
    #  - :trace e.g. true
    #  - :stop_signal e.g. :QUIT or :SIGQUIT
    def initialize(watchers = [], options = {})
      @options = options
      @pid = nil
      @stop_signal = options[:stop_signal] || DEFAULT_SIGNAL
      @options[:queue] ||= DEFAULT_QUEUE
      @options[:count] ||= DEFAULT_COUNT
      @options[:task] ||= (@options[:count].to_i == 1) ? DEFAULT_TASK_SINGLE : DEFAULT_TASK_MULTIPLE
      super
    end

    def start
      stop
      UI.info 'Starting up resque...'
      UI.info [ cmd, env.map{|v| v.join('=')} ].join(' ')

      # launch Resque worker
      @pid = spawn(env, cmd)
    end

    def stop
      if @pid
        UI.info 'Stopping resque...'
        ::Process.kill @stop_signal, @pid
        begin
          Timeout.timeout(15) do
            ::Process.wait @pid
          end
        rescue Timeout::Error
          UI.info 'Sending SIGKILL to resque, as it\'s taking too long to shutdown.'
          ::Process.kill :KILL, @pid
          ::Process.wait @pid
        end
        UI.info 'Stopped process resque'
      end
    rescue Errno::ESRCH
      UI.info 'Guard::Resque lost the Resque worker subprocess!'
    ensure
      @pid = nil
    end

    # Called on Ctrl-Z signal
    def reload
      UI.info 'Restarting resque...'
      restart
    end

    # Called on Ctrl-/ signal
    def run_all
      true
    end

    # Called on file(s) modifications
    def run_on_change(paths)
      restart
    end

    def restart
      stop
      start
    end

    private

    def cmd
      command = ['bundle exec rake', @options[:task].to_s]

      # trace setting
      command << '--trace' if @options[:trace]

      return command.join(' ')
    end

    def env
      var = Hash.new

      var['INVERVAL']  = @options[:interval].to_s    if @options[:interval]
      var['QUEUE']     = @options[:queue].to_s       if @options[:queue]
      var['COUNT']     = @options[:count].to_s       if @options[:count]
      var['RAILS_ENV'] = @options[:environment].to_s if @options[:environment]

      var['VERBOSE']  = '1' if @options[:verbose]
      var['VVERBOSE'] = '1' if @options[:vverbose]

      return var
    end
  end
end
{'fraction_non_alphanumeric': 0.12687844778390717, 'fraction_numerical': 0.002853338405934944, 'mean_word_length': 2.027058146229131, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '3581616', 'n_tokens_mistral': 1788, 'n_tokens_neox': 1728, 'n_words': 447}