Module: FlazmRubyHelpers::RakeHelper

Defined in:
lib/flazm_ruby_helpers/rake_helper.rb

Class Method Summary collapse

Class Method Details

.exec(command, stream: true) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/flazm_ruby_helpers/rake_helper.rb', line 12

def self.exec(command, stream: true)
  output = [] ; threads = [] ; status = nil
  Open3.popen3(command) do |_stdin, stdout, stderr, wait_thr|
    { out: stdout, err: stderr }.each do |_key, stream|
      threads << Thread.new do
        until (raw_line = stream.gets).nil?
          output << raw_line.to_s
          puts raw_line.to_s if stream
        end
      end
    end
    threads.each(&:join)
    status = wait_thr.value.success?
  end
  return output, status
end

.wait_for_urls(urls) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/flazm_ruby_helpers/rake_helper.rb', line 29

def self.wait_for_urls(urls)
  urls.each do |url|
    uri = URI(url)
    error = true
    Net::HTTP.start(uri.host, uri.port, read_timeout: 5, max_retries: 12) do |http|
      while error
        begin
          response = http.request(Net::HTTP::Get.new(uri))
          error = false
        rescue EOFError
          retry
        end
      end
      raise Exception unless response.code == '200'

      puts "up: #{url}"
    end
  end
end