Class: Runner
- Inherits:
-
Object
- Object
- Runner
- Defined in:
- lib/runner.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#runner_id ⇒ Object
readonly
Returns the value of attribute runner_id.
-
#runner_type ⇒ Object
readonly
Returns the value of attribute runner_type.
-
#tourists ⇒ Object
readonly
Returns the value of attribute tourists.
Instance Method Summary collapse
-
#initialize(host, tourists, number, runner_id, tour_list) ⇒ Runner
constructor
A new instance of Runner.
-
#run_tourists ⇒ Object
Dispatches to subclass run method.
Constructor Details
#initialize(host, tourists, number, runner_id, tour_list) ⇒ Runner
Returns a new instance of Runner.
7 8 9 10 11 |
# File 'lib/runner.rb', line 7 def initialize(host, tourists, number, runner_id, tour_list) @host, @tourists, @number, @runner_id, @tour_list = host, tourists, number, runner_id, tour_list @runner_type = self.send(:class).to_s log("Ready to run #{@runner_type}") end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
5 6 7 |
# File 'lib/runner.rb', line 5 def host @host end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
5 6 7 |
# File 'lib/runner.rb', line 5 def number @number end |
#runner_id ⇒ Object (readonly)
Returns the value of attribute runner_id.
5 6 7 |
# File 'lib/runner.rb', line 5 def runner_id @runner_id end |
#runner_type ⇒ Object (readonly)
Returns the value of attribute runner_type.
5 6 7 |
# File 'lib/runner.rb', line 5 def runner_type @runner_type end |
#tourists ⇒ Object (readonly)
Returns the value of attribute tourists.
5 6 7 |
# File 'lib/runner.rb', line 5 def tourists @tourists end |
Instance Method Details
#run_tourists ⇒ Object
Dispatches to subclass run method
14 15 16 17 18 19 20 21 22 23 24 25 26 27 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 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/runner.rb', line 14 def run_tourists log "Filtering on tours #{@tour_list.join(', ')}" unless @tour_list.to_a.empty? tourists,tours,passes,fails,errors = 0,0,0,0,0 1.upto(number) do |num| log("Starting #{@runner_type} run #{num}/#{number}") @tourists.each do |tourist_name| log("Starting run #{num}/#{number} of Tourist #{tourist_name}") tourists += 1 tourist = Tourist.make_tourist(tourist_name,@host,@tourists,@number,@runner_id) tourist.before_tours tourist.tours.each do |tour| times = Hash.new {|h,k| h[k] = {}} next if tour_limited_to(tour) begin tours += 1 times[tour][:started] = Time.now tourist.run_tour tour passes += 1 rescue TourBusException, WebratError => e log("********** FAILURE IN RUN! **********") log e. e.backtrace.each do |trace| log trace end fails += 1 rescue Exception => e log("*************************************") log("*********** ERROR IN RUN! ***********") log("*************************************") log e. e.backtrace.each do |trace| log trace end errors += 1 ensure times[tour][:finished] = Time.now times[tour][:elapsed] = times[tour][:finished] - times[tour][:started] end log("Finished run #{num}/#{number} of Tourist #{tourist_name}") end tourist.after_tours end log("Finished #{@runner_type} run #{num}/#{number}") end log("Finished all #{@runner_type} tourists.") [tourists,tours,passes,fails,errors] end |