Class: Webmeter::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/webmeter/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, paths) ⇒ Worker

Returns a new instance of Worker.



7
8
9
10
# File 'lib/webmeter/worker.rb', line 7

def initialize(host, paths)
  @host = host
  @paths = paths
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/webmeter/worker.rb', line 5

def host
  @host
end

#pathsObject

Returns the value of attribute paths.



5
6
7
# File 'lib/webmeter/worker.rb', line 5

def paths
  @paths
end

#user_agentObject

Returns the value of attribute user_agent.



5
6
7
# File 'lib/webmeter/worker.rb', line 5

def user_agent
  @user_agent
end

Instance Method Details

#runObject



20
21
22
# File 'lib/webmeter/worker.rb', line 20

def run
  Thread.new { work }
end

#workObject



12
13
14
15
16
17
18
# File 'lib/webmeter/worker.rb', line 12

def work
  @paths.each { |path|
    req = Net::HTTP::Get.new(path, {'User-Agent' => "Webmeter/worker-#{@user_agent}"})
    req.basic_auth('user', 'password')
    res = Net::HTTP.new(@host).start { |http| http.request(req) }
  }
end