2014-08-18 03:19:41 -04:00
module QueueClassicJobsManager
def setup
2016-08-06 12:41:18 -04:00
ENV [ " QC_DATABASE_URL " ] || = " postgres:///active_jobs_qc_int_test "
ENV [ " QC_RAILS_DATABASE " ] = " false "
ENV [ " QC_LISTEN_TIME " ] = " 0.5 "
2014-08-18 03:19:41 -04:00
ActiveJob :: Base . queue_adapter = :queue_classic
end
def clear_jobs
QC :: Queue . new ( " integration_tests " ) . delete_all
end
def start_workers
2016-08-06 12:41:18 -04:00
uri = URI . parse ( ENV [ " QC_DATABASE_URL " ] )
2016-10-28 23:05:58 -04:00
user = uri . user || ENV [ " USER " ]
2015-04-19 19:40:08 -04:00
pass = uri . password
db = uri . path [ 1 .. - 1 ]
%x{ #{ " PGPASSWORD= \" #{ pass } \" " if pass } psql -c 'drop database if exists " #{ db } "' -U #{ user } -t template1 }
%x{ #{ " PGPASSWORD= \" #{ pass } \" " if pass } psql -c 'create database " #{ db } "' -U #{ user } -t template1 }
QC :: Setup . create
2015-03-05 16:41:14 -05:00
QC . default_conn_adapter . disconnect
QC . default_conn_adapter = nil
2014-08-18 03:19:41 -04:00
@pid = fork do
2016-08-06 12:41:18 -04:00
worker = QC :: Worker . new ( q_name : " integration_tests " )
2014-08-18 03:19:41 -04:00
worker . start
end
2015-04-19 19:40:08 -04:00
rescue PG :: ConnectionBad
puts " Cannot run integration tests for queue_classic. To be able to run integration tests for queue_classic you need to install and start postgresql. \n "
exit
2014-08-18 03:19:41 -04:00
end
def stop_workers
2016-08-06 12:41:18 -04:00
Process . kill " HUP " , @pid
2014-08-18 03:19:41 -04:00
end
end