Class: Benchmark::HTTP::Command::Wait

Inherits:
Samovar::Command
  • Object
show all
Defined in:
lib/benchmark/http/command/wait.rb

Instance Method Summary collapse

Instance Method Details

#callObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/benchmark/http/command/wait.rb', line 55

def call
	Sync do |task|
		barrier = Async::Barrier.new
		
		@hosts.each do |host|
			run(host, parent: barrier)
		end
		
		barrier.wait
	end
end

#run(url, parent: Async::Task.current) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/benchmark/http/command/wait.rb', line 28

def run(url, parent: Async::Task.current)
	endpoint = Async::HTTP::Endpoint.parse(url)
	request_path = endpoint.url.request_uri
	maximum_wait = @options[:wait]
	
	parent.async do
		clock = Async::Clock.start
		
		client = Async::HTTP::Client.new(endpoint)
		
		begin
			client.get(request_path).tap(&:finish)
		rescue => error
			if clock.total > maximum_wait
				raise
			else
				sleep 0.01
				retry
			end
		end
		
		Console.logger.info(self) {"#{url} is ready after #{clock.total} seconds."}
	ensure
		client.close
	end
end