Sha256: 04dc4c41d58a09ebd0486c9d70a5f0e1f774165ffc169830b05bb61b65a9f4a9

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

module Minke
  module Helpers
    class Helper
      ##
      # copy assets from one location to another
      def copy_assets from, to
        directory = to
        if File.directory?(to)
          directory = File.dirname(to)
        end

        Dir.mkdir directory unless Dir.exist? to
        FileUtils.cp from, to
      end
 
      ##
      # invoke a rake task
      def invoke_task task
        Rake::Task[task].invoke
      end

      def load_consul_data server, config_file
        wait_for_HTTPOK "#{server}/v1/status/leader", 0, 1
        loader = ConsulLoader::Loader.new(ConsulLoader::ConfigParser.new)
        puts config_file
        loader.load_config config_file, server
      end

      def execute_shell_command command
        puts `#{command}`
        $?.exitstatus
      end

      def fatal_error message
        abort message
      end

      ##
      # waits until a 200 response is received from the given url
      def wait_for_HTTPOK url, count, successes = 0
        begin
          response = RestClient.send("get", url)
        rescue

        end

        if response == nil || !response.code.to_i == 200
          puts "Waiting for server #{url} to start"
          sleep 1
          if count < 180
            wait_for_HTTPOK url, count + 1
          else
            raise 'Server failed to start'
          end
        else
          if successes > 0
            puts "Server: #{url} passed health check, #{successes} checks to go..."
            sleep 1
            wait_for_HTTPOK url, count + 1, successes - 1
          else
            puts "Server: #{url} healthy"
          end
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
minke-1.0.0 lib/minke/helpers/helper.rb