<commit_before>require 'guard/compat/plugin'

module Guard
  class WebsocketRails < Plugin
    attr_reader :options

    MAX_WAIT_COUNT = 10
    DEFAULT_OPTIONS = {
      environment: 'development',
      bundler: false,
      zeus: false,
      pid_file: nil,
      redis_port: 6379,
      timeout: 30
    }

    def initialize(options={})
      super
      @options = DEFAULT_OPTIONS.merge(options)
      @root = options[:root] ? File.expand_path(options[:root]) : Dir.pwd
    end

    def start
      if ( redis_guards = Guard.state.session.plugins.all('redis') ).empty?
        UI.warning "[Guard::WebsocketRails::Error] Guard::Redis is not running."
        if `lsof -Pi :#{options[:redis_port]} -sTCP:LISTEN -t`.strip.length == 0
          UI.error "[Guard::WebsocketRails::Error] You must boot redis " +
            "on port #{options[:redis_port]} before starting the websocket server."
          return false
        end
      end
      if options[:zeus] && !wait_for_zeus
        UI.info "[Guard::WebsocketRails::Error] Could not find zeus socket file."
        return false
      end
      run_wsr_command!('start_server')
      wait_for_pid
      Compat::UI.info "Websocket standalone server started (#{options[:environment]})"
      if redis_guards.any?
        # UI.info "Guard callbacks before starting: #{Guard::Plugin.callbacks}"
        # UI.info "Guard::Redis callbacks before starting: #{Guard::Redis.callbacks}"
        on_stop = -> { UI.info 'I GET CALLED!!'; stop }
        Guard::Redis.add_callback on_stop, redis_guards[0], :stop_begin
        # UI.info "All Guard callbacks: #{Guard::Plugin.callbacks}"
        # UI.info "All Guard::Redis callbacks: #{Guard::Redis.callbacks}"
        # UI.info "Redis callbacks: #{redis_guards[0].callbacks}"
      end
    end

    def stop
      return unless has_pid?
      run_wsr_command!('stop_server')
      wait_for_no_pid
      UI.info "Websocket standalone server stopped (#{options[:environment]})"<commit_msg>Lambdas definitely don't work there.  This version should work well.<commit_after>require 'guard/compat/plugin'

module Guard
  class WebsocketRails < Plugin
    attr_reader :options

    MAX_WAIT_COUNT = 10
    DEFAULT_OPTIONS = {
      environment: 'development',
      bundler: false,
      zeus: false,
      pid_file: nil,
      redis_port: 6379,
      timeout: 30
    }

    def initialize(options={})
      super
      @options = DEFAULT_OPTIONS.merge(options)
      @root = options[:root] ? File.expand_path(options[:root]) : Dir.pwd
    end

    def start
      if ( redis_guards = Guard.state.session.plugins.all('redis') ).empty?
        UI.warning "[Guard::WebsocketRails::Error] Guard::Redis is not running."
        if `lsof -Pi :#{options[:redis_port]} -sTCP:LISTEN -t`.strip.length == 0
          UI.error "[Guard::WebsocketRails::Error] You must boot redis " +
            "on port #{options[:redis_port]} before starting the websocket server."
          return false
        end
      end
      if options[:zeus] && !wait_for_zeus
        UI.info "[Guard::WebsocketRails::Error] Could not find zeus socket file."
        return false
      end
      run_wsr_command!('start_server')
      wait_for_pid
      UI.info "Websocket standalone server started (#{options[:environment]})"
      if redis_guards.any?
        stop_the_server = Proc.new do
          UI.debug 'Shutting down WebsocketRails server before Redis stops.'
          stop
        end
        Guard::Redis.add_callback stop_the_server, redis_guards[0], :stop_begin
      end
    end

    def stop
      return unless has_pid?
      run_wsr_command!('stop_server')
      wait_for_no_pid
      UI.info "Websocket standalone server stopped (#{options[:environment]})"
{'fraction_non_alphanumeric': 0.11295948484035417, 'fraction_numerical': 0.005634558626240944, 'mean_word_length': 2.792472024415056, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '1435886', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1143, 'n_words': 281}