2014-08-18 03:19:41 -04:00
|
|
|
module QueJobsManager
|
|
|
|
def setup
|
2016-08-06 12:41:18 -04:00
|
|
|
require "sequel"
|
2014-08-18 03:19:41 -04:00
|
|
|
ActiveJob::Base.queue_adapter = :que
|
2015-04-19 19:40:08 -04:00
|
|
|
Que.mode = :off
|
|
|
|
Que.worker_count = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def clear_jobs
|
|
|
|
Que.clear!
|
|
|
|
end
|
|
|
|
|
|
|
|
def start_workers
|
2016-08-06 12:41:18 -04:00
|
|
|
que_url = ENV["QUE_DATABASE_URL"] || "postgres:///active_jobs_que_int_test"
|
2014-08-18 03:19:41 -04:00
|
|
|
uri = URI.parse(que_url)
|
2016-10-28 23:05:58 -04:00
|
|
|
user = uri.user || ENV["USER"]
|
2014-08-18 03:19:41 -04:00
|
|
|
pass = uri.password
|
|
|
|
db = uri.path[1..-1]
|
2014-09-27 08:25:03 -04:00
|
|
|
%x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'drop database if exists "#{db}"' -U #{user} -t template1}
|
2014-08-18 03:19:41 -04:00
|
|
|
%x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'create database "#{db}"' -U #{user} -t template1}
|
|
|
|
Que.connection = Sequel.connect(que_url)
|
|
|
|
Que.migrate!
|
|
|
|
|
|
|
|
@thread = Thread.new do
|
|
|
|
loop do
|
2015-05-03 17:01:57 -04:00
|
|
|
Que::Job.work
|
2014-08-18 03:19:41 -04:00
|
|
|
sleep 0.5
|
|
|
|
end
|
|
|
|
end
|
2015-04-19 19:40:08 -04:00
|
|
|
|
|
|
|
rescue Sequel::DatabaseConnectionError
|
|
|
|
puts "Cannot run integration tests for que. To be able to run integration tests for que you need to install and start postgresql.\n"
|
|
|
|
exit
|
2014-08-18 03:19:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def stop_workers
|
|
|
|
@thread.kill
|
|
|
|
end
|
|
|
|
end
|