module SneakersJobsManager
Public Instance Methods
can_run?()
click to toggle source
# File activejob/test/support/integration/adapters/sneakers.rb, line 69 def can_run? begin bunny_publisher rescue return false end true end
clear_jobs()
click to toggle source
# File activejob/test/support/integration/adapters/sneakers.rb, line 36 def clear_jobs bunny_queue.purge end
setup()
click to toggle source
# File activejob/test/support/integration/adapters/sneakers.rb, line 18 def setup ActiveJob::Base.queue_adapter = :sneakers Sneakers.configure heartbeat: 2, amqp: "amqp://guest:guest@localhost:5672", vhost: "/", exchange: "active_jobs_sneakers_int_test", exchange_type: :direct, daemonize: true, threads: 1, workers: 1, pid_path: Quails.root.join("tmp/sneakers.pid").to_s, log: Quails.root.join("log/sneakers.log").to_s unless can_run? puts "Cannot run integration tests for sneakers. To be able to run integration tests for sneakers you need to install and start rabbitmq.\n" exit end end
start_workers()
click to toggle source
# File activejob/test/support/integration/adapters/sneakers.rb, line 40 def start_workers @pid = fork do queues = %w(integration_tests) workers = queues.map do |q| worker_klass = "ActiveJobWorker" + Digest::MD5.hexdigest(q) Sneakers.const_set(worker_klass, Class.new(ActiveJob::QueueAdapters::SneakersAdapter::JobWrapper) do from_queue q end) end Sneakers::Runner.new(workers).run end begin Timeout.timeout(10) do while bunny_queue.status[:consumer_count] == 0 sleep 0.5 end end rescue Timeout::Error stop_workers raise "Failed to start sneakers worker" end end
stop_workers()
click to toggle source
# File activejob/test/support/integration/adapters/sneakers.rb, line 63 def stop_workers Process.kill "TERM", @pid Process.kill "TERM", File.open(Quails.root.join("tmp/sneakers.pid").to_s).read.to_i rescue end
Private Instance Methods
bunny_publisher()
click to toggle source
# File activejob/test/support/integration/adapters/sneakers.rb, line 79 def bunny_publisher @bunny_publisher ||= begin p = ActiveJob::QueueAdapters::SneakersAdapter::JobWrapper.send(:publisher) p.safe_ensure_connected p end end
bunny_queue()
click to toggle source
# File activejob/test/support/integration/adapters/sneakers.rb, line 87 def bunny_queue @queue ||= bunny_publisher.exchange.channel.queue "integration_tests", durable: true end