lib/rocket_job/performance.rb in rocketjob-3.4.3 vs lib/rocket_job/performance.rb in rocketjob-3.5.0

- old
+ new

@@ -16,11 +16,13 @@ end # Loads the queue with jobs to be processed once the queue is loaded. # Retain the first and last job for timings, all others are destroyed on completion. def run_test_case(count = self.count) - raise 'Please start servers before starting the performance test' if RocketJob::Server.where(:state.in => ['running', 'paused']).count == 0 + if RocketJob::Server.where(:state.in => %w[running paused]).count.zero? + raise 'Please start servers before starting the performance test' + end count_running_workers puts 'Waiting for workers to pause' RocketJob::Server.pause_all @@ -31,25 +33,23 @@ running = 0 RocketJob::Server.paused.each do |server| running += server.heartbeat.workers unless server.zombie? end puts "Waiting for #{running} workers" - break if running == 0 + break if running.zero? sleep 1 end puts 'Enqueuing jobs' first = RocketJob::Jobs::SimpleJob.create!(priority: 1, destroy_on_complete: false) - (count - 2).times { |i| RocketJob::Jobs::SimpleJob.create! } + (count - 2).times { RocketJob::Jobs::SimpleJob.create! } last = RocketJob::Jobs::SimpleJob.create!(priority: 100, destroy_on_complete: false) puts 'Resuming workers' RocketJob::Server.resume_all - while (!last.reload.completed?) - sleep 3 - end + sleep 3 until last.reload.completed? duration = last.reload.completed_at - first.reload.started_at first.destroy last.destroy @@ -65,17 +65,23 @@ end # Parse command line options def parse(argv) parser = OptionParser.new do |o| - o.on('-c', '--count COUNT', 'Count of jobs to enqueue') do |arg| + o.on('-c', + '--count COUNT', + 'Count of jobs to enqueue') do |arg| self.count = arg.to_i end - o.on('-m', '--mongo MONGO_CONFIG_FILE_NAME', 'Path and filename of config file. Default: config/mongoid.yml') do |arg| + o.on('-m', + '--mongo MONGO_CONFIG_FILE_NAME', + 'Path and filename of config file. Default: config/mongoid.yml') do |arg| self.mongo_config = arg end - o.on('-e', '--environment ENVIRONMENT', 'The environment to run the app on (Default: RAILS_ENV || RACK_ENV || development)') do |arg| + o.on('-e', + '--environment ENVIRONMENT', + 'The environment to run the app on (Default: RAILS_ENV || RACK_ENV || development)') do |arg| self.environment = arg end end parser.banner = 'rocketjob_perf <options>' parser.on_tail '-h', '--help', 'Show help' do @@ -93,8 +99,7 @@ self.servers += 1 self.workers += server.heartbeat.workers end puts "Running: #{workers} workers, distributed across #{servers} servers" end - end end