2014-08-18 03:19:41 -04:00
|
|
|
module ResqueJobsManager
|
|
|
|
def setup
|
|
|
|
ActiveJob::Base.queue_adapter = :resque
|
2014-12-12 21:05:25 -05:00
|
|
|
Resque.redis = Redis::Namespace.new 'active_jobs_int_test', redis: Redis.connect(url: "redis://127.0.0.1:6379/12", :thread_safe => true)
|
2014-08-18 03:19:41 -04:00
|
|
|
Resque.logger = Rails.logger
|
|
|
|
unless can_run?
|
|
|
|
puts "Cannot run integration tests for resque. To be able to run integration tests for resque you need to install and start redis.\n"
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def clear_jobs
|
|
|
|
Resque.queues.each { |queue_name| Resque.redis.del "queue:#{queue_name}" }
|
|
|
|
Resque.redis.keys("delayed:*").each { |key| Resque.redis.del "#{key}" }
|
|
|
|
Resque.redis.del "delayed_queue_schedule"
|
|
|
|
end
|
|
|
|
|
|
|
|
def start_workers
|
|
|
|
@resque_thread = Thread.new do
|
2014-09-27 08:25:03 -04:00
|
|
|
w = Resque::Worker.new("integration_tests")
|
|
|
|
w.term_child = true
|
|
|
|
w.work(0.5)
|
2014-08-18 03:19:41 -04:00
|
|
|
end
|
|
|
|
@scheduler_thread = Thread.new do
|
|
|
|
Resque::Scheduler.configure do |c|
|
|
|
|
c.poll_sleep_amount = 0.5
|
|
|
|
c.dynamic = true
|
2014-09-27 08:25:03 -04:00
|
|
|
c.quiet = true
|
2014-08-18 03:19:41 -04:00
|
|
|
c.logfile = nil
|
|
|
|
end
|
|
|
|
Resque::Scheduler.master_lock.release!
|
|
|
|
Resque::Scheduler.run
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop_workers
|
|
|
|
@resque_thread.kill
|
|
|
|
@scheduler_thread.kill
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_run?
|
|
|
|
begin
|
|
|
|
Resque.redis.client.connect
|
2014-10-19 13:47:22 -04:00
|
|
|
rescue
|
2014-08-18 03:19:41 -04:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|