Sha256: 7ba2b7aa14ef998db130cff33c7dffeb4c172e6148197442128c1beb7b3df95a
Contents?: true
Size: 1.2 KB
Versions: 2
Compression:
Stored size: 1.2 KB
Contents
# frozen_string_literal: true require 'sidekiq/cli' require 'sidekiq/launcher' require 'sidekiq_unique_jobs/timeout' module Sidekiq class Simulator include SidekiqUniqueJobs::Logging include SidekiqUniqueJobs::Timeout attr_reader :queues, :launcher def self.process_queue(queue) new(queue).process_queue { yield } end def initialize(queue) @queues = Array(queue).uniq @launcher = Sidekiq::Launcher.new(sidekiq_options(queues)) end def process_queue run_launcher yield ensure terminate_launcher end private def run_launcher run_launcher! rescue Timeout::Error => exception log_warn('Timeout while starting Sidekiq') log_warn(exception) end def run_launcher! using_timeout(15) do launcher.run sleep 0.001 until alive? end end def terminate_launcher launcher.stop end def alive? launcher.manager.workers.any? end def stopped? !alive? end def sidekiq_options(queues = []) { queues: queues, concurrency: 3, timeout: 3, verbose: false, logfile: './tmp/sidekiq.log' } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sidekiq-unique-jobs-6.0.0.rc2 | lib/sidekiq/simulator.rb |
sidekiq-unique-jobs-6.0.0.rc1 | lib/sidekiq/simulator.rb |