Sha256: 8bd947da3394607a1b098d34a60c04b997d64083ae4eb74f6f2b998e779c4229

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

module LitmusPaper
  class StatusFile
    attr_reader :health

    def self.global_down_file
      new("global_down", 0)
    end

    def self.global_up_file
      new("global_up", 100)
    end

    def self.service_down_file(service_name)
      new("#{service_name}_down", 0)
    end

    def self.service_up_file(service_name)
      new("#{service_name}_up", 100)
    end

    def self.priority_check_order_for_service(service_name)
      [
        global_down_file,
        global_up_file,
        service_down_file(service_name),
        service_up_file(service_name)
      ]
    end

    def initialize(filename, health)
      @path = File.join(LitmusPaper.config_dir, filename)
      @health = health
    end

    def content
      File.read(@path).chomp
    end

    def create(reason)
      FileUtils.mkdir_p(File.dirname(@path))
      File.open(@path, 'w') do |file|
        file.puts(reason)
      end
    end

    def delete
      FileUtils.rm(@path)
    end

    def exists?
      File.exists?(@path)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
litmus_paper-0.6.2 lib/litmus_paper/status_file.rb
litmus_paper-0.6.1 lib/litmus_paper/status_file.rb
litmus_paper-0.6.0 lib/litmus_paper/status_file.rb
litmus_paper-0.5.0 lib/litmus_paper/status_file.rb
litmus_paper-0.4.0 lib/litmus_paper/status_file.rb