Sha256: d4ad2b3fa86a6175725b216b34e928eb9bac8f6497180595be4ef2c93b25ccc5

Contents?: true

Size: 1.7 KB

Versions: 7

Compression:

Stored size: 1.7 KB

Contents

require 'sidekiq/cli'
require 'sidekiq/api'

module Sidekiq
  class CLI
    def boot_system_with_rescue
      boot_system_without_rescue
    rescue => e
      raise unless /Application has been already initialized./ =~ e.message
    end
    alias_method_chain :boot_system, :rescue
  end
end

module SidekiqJobsManager

  def setup
    ActiveJob::Base.queue_adapter = :sidekiq
    unless can_run?
      puts "Cannot run integration tests for sidekiq. To be able to run integration tests for sidekiq you need to install and start redis.\n"
      exit
    end
  end

  def clear_jobs
    Sidekiq::ScheduledSet.new.clear
    Sidekiq::Queue.new("integration_tests").clear
  end

  def start_workers
    fork do
      sidekiq = Sidekiq::CLI.instance
      logfile = Rails.root.join("log/sidekiq.log").to_s
      pidfile = Rails.root.join("tmp/sidekiq.pid").to_s
      sidekiq.parse([ "--require", Rails.root.to_s,
                      "--queue",   "integration_tests",
                      "--logfile", logfile,
                      "--pidfile", pidfile,
                      "--environment", "test",
                      "--concurrency", "1",
                      "--timeout", "1",
                      "--daemon",
                      ])
      require 'celluloid'
      require 'sidekiq/scheduled'
      Sidekiq.poll_interval = 0.5
      Sidekiq::Scheduled.const_set :INITIAL_WAIT, 1
      sidekiq.run
    end
    sleep 1
  end

  def stop_workers
    pidfile = Rails.root.join("tmp/sidekiq.pid").to_s
    Process.kill 'TERM', File.open(pidfile).read.to_i
    FileUtils.rm_f pidfile
  rescue
  end

  def can_run?
    begin
      Sidekiq.redis(&:info)
      Sidekiq.logger = nil
    rescue
      return false
    end
    true
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
activejob-retry-0.6.3 test/support/integration/adapters/sidekiq.rb
activejob-retry-0.6.2 test/support/integration/adapters/sidekiq.rb
activejob-retry-0.6.1 test/support/integration/adapters/sidekiq.rb
activejob-retry-0.6.0 test/support/integration/adapters/sidekiq.rb
activejob-retry-0.5.1 test/support/integration/adapters/sidekiq.rb
activejob-retry-0.5.0 test/support/integration/adapters/sidekiq.rb
activejob-retry-0.4.2 test/support/integration/adapters/sidekiq.rb