Skip to content

Instantly share code, notes, and snippets.

@danarnold
Last active May 3, 2018 20:01
Show Gist options
  • Save danarnold/13a25ac80af3e5b00b37 to your computer and use it in GitHub Desktop.
Save danarnold/13a25ac80af3e5b00b37 to your computer and use it in GitHub Desktop.
Run sidekiq queues for a project, with optional 'only' and 'except' options, based off the project's Procfile
#!/usr/bin/env ruby
abort('Procfile not found!') unless File.exists? 'Procfile'
if ARGV.select { |a| a == 'only' || a == 'except' }.size > 1
abort('Invalid arguments')
end
if ARGV.first == 'only'
@only = ARGV[1..-1]
elsif ARGV.first == 'except'
@except = ARGV[1..-1]
end
@queues = ['default']
File.foreach('Procfile') do |line|
match = line.match(/sidekiq -q (\w+)/)
if match
@queues << match[1]
end
end
@queues.uniq!
if @only
@queues = @only & @queues
elsif @except
@queues -= @except
end
abort('Queues empty') unless @queues.size > 0
@queues.map! { |q| "-q #{q}" }
command = "bundle exec sidekiq #{@queues.join(' ')}"
puts command
exec command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment