Skip to content

Instantly share code, notes, and snippets.

@wakproductions
Last active March 18, 2024 14:08
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save wakproductions/56482d9b8b00ec2378206f03327abcd1 to your computer and use it in GitHub Desktop.
Save wakproductions/56482d9b8b00ec2378206f03327abcd1 to your computer and use it in GitHub Desktop.
Sidekiq Commands Cheat Sheet

Start workers:

This will run the loans queue with the weight of 5

bundle exec sidekiq -q loans,5

SO: How to run Sidekiq in production

Stopping Sidekiq

ps -ef | grep sidekiq | grep -v grep | awk '{print $2}' | xargs kill -9

See the pid:

 (add_sidekiq_134)$ ps -ef | grep sidekiq
  501 89943  4082   0  5:10PM ttys002    0:03.19 sidekiq 4.2.2 common_crawl_extractor [3 of 25 busy]  
  501 89957 89943   0  5:10PM ttys002    0:00.01 /Users/wkotzan/.rvm/gems/ruby-2.3.1/gems/rb-fsevent-0.9.7/bin/fsevent_watch --latency 0.1 /Users/wkotzan/.rvm/gems/ruby-2.3.1/gems/sidekiq-4.2.2
  501 89979 71666   0  5:10PM ttys011    0:00.00 grep sidekiq

Shut down pid (stop Sidekiq from picking up new workers):

kill -USR1 89943

Shut down pid (force shutdown of running workers and push them back into the queue):

kill -TERM 89943

Empty items in a queue:

[2] pry(main)> q = Sidekiq::Queue.all
=> [#<Sidekiq::Queue:0x007ff683761ef8 @name="default", @rname="queue:default">]
[3] pry(main)> q.first.size
=> 4
[4] pry(main)> q.first.clear
=> [1, true]
[5] pry(main)> q.first.size
=> 0

List Queues & Size

Sidekiq::Queue.all.each { |q| puts "#{q.name}: #{Sidekiq::Queue.new(q.name).size}" }

See whats in a queue

Sidekiq::Queue.new(<queue_name>).each { |job| puts "#{job.class}: #{job.args}" }

Check Configuration

> Sidekiq.options
=> {:queues=>[],
 :labels=>[],
 :concurrency=>25,
 :require=>".",
 :environment=>nil,
 :timeout=>8,
 :poll_interval_average=>nil,
 :average_scheduled_poll_interval=>15,
 :error_handlers=>[#<Sidekiq::ExceptionHandler::Logger:0x007f844aa7bae0>],
 :lifecycle_events=>{:startup=>[], :quiet=>[], :shutdown=>[], :heartbeat=>[]},
 :dead_max_jobs=>10000,
 :dead_timeout_in_seconds=>15552000,
 :reloader=>#<Proc:0x007f8449a8d480@/Users/wkotzan/.rvm/gems/ruby-2.3.1@banks/gems/sidekiq-4.2.7/lib/sidekiq.rb:35>,
 :executor=>#<Proc:0x007f8449a8d458@/Users/wkotzan/.rvm/gems/ruby-2.3.1@banks/gems/sidekiq-4.2.7/lib/sidekiq.rb:36>}
 
 > Sidekiq.redis { |c| puts c.client.location }
localhost:6379

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