Skip to content

Instantly share code, notes, and snippets.

@ericchen
Last active March 15, 2016 10:20
Show Gist options
  • Save ericchen/eeff0c1883d8a6da76cd to your computer and use it in GitHub Desktop.
Save ericchen/eeff0c1883d8a6da76cd to your computer and use it in GitHub Desktop.
sidekiq使用
启动sidekiq

bundle exec sidekiq -c 10 -e production -L log/sidekiq.log -d

队列查询

# See workers
Sidekiq::Client.registered_workers

# See queues
Sidekiq::Client.registered_queues

# See all jobs for one queue
Sidekiq.redis { |r| r.lrange "queue:app_queue", 0, -1 }

# See all jobs in all queues
Sidekiq::Client.registered_queues.each do |q|
  Sidekiq.redis { |r| r.lrange "queue:#{q}", 0, -1 }
end

# Remove a queue and all of its jobs
Sidekiq.redis do |r| 
  r.srem "queues", "app_queue"
  r.del  "queue:app_queue"
end


require 'sidekiq/api'
# get a handle to the default queue
default_queue = Sidekiq::Queue.new 

# get a handle to the mailer queue
mailer_queue = Sidekiq::Queue.new("mailer") 

# How many jobs are in the default queue?
default_queue.size # => 1001

# How many jobs are in the mailer queue?
mailer_queue.size # => 50

#Deletes all Jobs in a Queue, by removing the queue.    
default_queue.clear

stats = Sidekiq::Stats.new

# Get the number of jobs that have been processed.
stats.processed # => 100

# Get the number of jobs that have failed.    
stats.failed # => 3

# Get the queues with name and number enqueued.
stats.queues # => { "default" => 1001, "email" => 50 }

#Gets the number of jobs enqueued in all queues (does NOT include retries and scheduled jobs).
stats.enqueued # => 1051 

##参考链接

  1. Sidekiq Best Practices
  2. Storing Data with Redis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment