Skip to content

Instantly share code, notes, and snippets.

@schovi
Created March 17, 2017 22:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schovi/252f63366b4549d6e6a3b0170df8d836 to your computer and use it in GitHub Desktop.
Save schovi/252f63366b4549d6e6a3b0170df8d836 to your computer and use it in GitHub Desktop.
Configure sidekiq via ENV variables
Sidekiq.configure_server do |config|
ENV["SIDEKIQ_NAMESPACE"] && config.options[:namespace] = ENV["SIDEKIQ_NAMESPACE"]
ENV["SIDEKIQ_CONCURRENCY"] && config.options[:concurrency] = ENV["SIDEKIQ_CONCURRENCY"].to_i
ENV["SIDEKIQ_VERBOSE"] && config.options[:verbose] = ENV["SIDEKIQ_VERBOSE"] === 'true'
ENV["SIDEKIQ_LOGFILE"] && config.options[:logfile] = ENV["SIDEKIQ_LOGFILE"]
ENV["SIDEKIQ_PIDFILE"] && config.options[:pidfile] = ENV["SIDEKIQ_PIDFILE"]
config.options[:strict] = true
if ENV["SIDEKIQ_QUEUES"]
queues = []
ENV["SIDEKIQ_QUEUES"].split(/\s+/).each do |queue_weighted|
queue, count = queue_weighted.split(",")
count = count.to_i
if count > 0
config.options[:strict] = false
end
[count, 1].max.times do
queues.push(queue)
end
end
config.options[:queues] = queues
end
end
@thegreyfellow
Copy link

thegreyfellow commented May 18, 2019

queues should look like this:

SIDEKIQ_QUEUES: "default,2 critical,4 another_queue"

@pboling
Copy link

pboling commented Feb 28, 2024

Neat!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment