Class: WSDirector::Runner
- Inherits:
-
Object
- Object
- WSDirector::Runner
- Defined in:
- lib/wsdirector/runner.rb
Overview
Initiates all clients as a separate tasks (=threads)
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(scenario, url:, scale: 1, sync_timeout: 5, logger: nil, colorize: false) ⇒ Runner
constructor
A new instance of Runner.
Constructor Details
#initialize(scenario, url:, scale: 1, sync_timeout: 5, logger: nil, colorize: false) ⇒ Runner
Returns a new instance of Runner.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/wsdirector/runner.rb', line 20 def initialize(scenario, url:, scale: 1, sync_timeout: 5, logger: nil, colorize: false) @scenario = scenario @url = url @scale = scale @logger = logger @colorize = colorize @total_count = scenario["total"] @global_holder = ClientsHolder.new(total_count, sync_timeout:) @results_holder = ResultsHolder.new end |
Instance Method Details
#execute ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/wsdirector/runner.rb', line 31 def execute Thread.abort_on_exception = true num = 0 tasks = scenario["clients"].flat_map do |client_config| name = client_config.fetch("name") result = Result.new(name) results_holder << result Array.new(client_config.fetch("multiplier")) do num += 1 id = "#{name}_#{num}" Thread.new do Task.new(client_config.deep_dup, id:, colorize:, global_holder:, result:, scale:, logger:) .run(url) end end end tasks.each(&:join) results_holder end |