Sha256: 7caac164c5ef8fdfa0430ac10d2d965f1d65fab05f20361d33a80dd2ea623ecd

Contents?: true

Size: 981 Bytes

Versions: 2

Compression:

Stored size: 981 Bytes

Contents

module Lacquer
  class Varnish
    def stats
      stats = send_command('stats').split("\n")
      stats.shift
      
      stats = stats.collect do |stat|
        stat = stat.strip.match(/(\d+)\s+(.+)$/)
        { :key => stat[2], :value => stat[1] }
      end
    end

    def purge(path)
      (send_command('url.purge ' << path) == '200 0') ? true : false
    end

  private

    # Sends commands over telnet to varnish servers listed in the config.
    def send_command(command)
      Lacquer.configuration.varnish_servers.each do |server|
        begin
          connection = Net::Telnet.new(
            'Host' => server[:host],
            'Port' => server[:port],
            'Timeout' => server[:timeout] || 5)
          connection.cmd(command) do |c|
            return c.strip
          end
        rescue Exception => e
          raise VarnishError.new("Error while trying to connect to #{server[:host]}:#{server[:port]} #{e}")
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lacquer-0.2.3 lib/lacquer/varnish.rb
lacquer-0.2.2 lib/lacquer/varnish.rb