Start multiple consumers with a single command
Closed this issue · 0 comments
laurynas commented
I'm not using Racecar
, just want to share the script which I implemented when testing Racecar
. It is just a proof of concept, never used in production. Just sharing it in case someone would find it useful.
You allows starting multiple consumer processes with a single script.
bin/racecar_pool
:
#!/usr/bin/env ruby
require 'yaml'
rails_env = ENV.fetch('RAILS_ENV', 'development')
config_file = File.expand_path('../config/racecar_pool.yml', __dir__)
config = YAML
.load_file(config_file)
.fetch(rails_env)
consumers = config.fetch('consumers')
pids = consumers.map do |consumer|
spawn("bundle exec racecar #{consumer}")
end
signals = %w(TERM INT HUP QUIT SIGUSR1)
signals.each do |signal|
Signal.trap(signal) do
Process.kill(signal, *pids)
end
end
Process.waitall
Consumers configuration file, config/racecar_pool.yml
:
default: &default
consumers:
- PingConsumer
- MyConsumer
development:
<<: *default
test:
<<: *default
production:
<<: *default