Sha256: 9418841527625b78fcdf57534f544d575fdace4391045b0caeb7c16557531833

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module LitmusPaper
  class AgentCheckHandler
    def self.handle(service)
      @cache ||= LitmusPaper::Cache.new(
        LitmusPaper.cache_location,
        "litmus_agent_cache",
        LitmusPaper.cache_ttl
      )
      output = []

      if !service
        return "failed#BAD_INPUT"
      end

      health = @cache.get(service)
      if !health
        @cache.set(
          service,
          health = LitmusPaper.check_service(service)
        )
      end

      if health.nil?
        output << "failed#NOT_FOUND"
      else
        case health.direction
        when :up, :health
          output << "ready" # administrative state
          output << "up" # operational state
        when :down
          output << "drain" # administrative state
        when :none
          if health.ok?
            output << "ready" # administrative state
            output << "up" # operational state
          else
            output << "down" # operational state
          end
        end
        output << "#{health.value.to_s}%"
      end
      output.join("\t")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
litmus_paper-1.6.2 lib/litmus_paper/agent_check_handler.rb