#!/usr/bin/env ruby # frozen_string_literal: true # Usage: time RUBYOPT="-W0" bin/quiqload require_relative '../lib/quiq' require_relative '../testapp/config/environment.rb' require 'optparse' options = { number: 10_000, wait: 1 } OptionParser.new do |opts| opts.banner = 'Usage: quiqload [options]' opts.on('-n', '--number JOBS', Integer, 'Number of jobs to enqueue') do |number| options[:number] = number.to_i end opts.on('-w', '--wait DURATION', Integer, 'Idle time within each job (in seconds)') do |wait| options[:wait] = wait.to_i end opts.on_tail('-h', '--help', 'Show this message') do puts opts exit end end.parse! Quiq.logger.info("Enqueuing #{options[:number]} jobs") options[:number].times { |i| TestJob.perform_later(i, options[:wait]) } Thread.new do loop do queue_size = Async do queue = Quiq::Queue.processing_name('default') Quiq.redis.llen queue end.wait if queue_size.zero? Quiq.logger.info("Done processing #{options[:number]} jobs") break end sleep 0.1 end end.join