aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test/support/integration/adapters/qu.rb
blob: b2f63d8f9498b7eb326e95cd92cff10d2e7dd9af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true
module QuJobsManager
  def setup
    require "qu-rails"
    require "qu-redis"
    ActiveJob::Base.queue_adapter = :qu
    ENV["REDISTOGO_URL"] = "redis://127.0.0.1:6379/12"
    backend = Qu::Backend::Redis.new
    backend.namespace = "active_jobs_int_test"
    Qu.backend  = backend
    Qu.logger   = Rails.logger
    Qu.interval = 0.5
    unless can_run?
      puts "Cannot run integration tests for qu. To be able to run integration tests for qu you need to install and start redis.\n"
      exit
    end
  end

  def clear_jobs
    Qu.clear "integration_tests"
  end

  def start_workers
    @thread = Thread.new { Qu::Worker.new("integration_tests").start }
  end

  def stop_workers
    @thread.kill
  end

  def can_run?
    begin
      Qu.backend.connection.client.connect
    rescue
      return false
    end
    true
  end
end