Answers:
我从未使用过Sidekiq,因此可能有一些方法只用于查看排队的作业,但实际上它们只是Redis命令的包装,因为基本上所有Sidekiq(和Resque)都是:
# 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
不幸的是,删除特定作业要困难一些,因为您必须复制其确切值:
# Remove a specific job from a queue
Sidekiq.redis { |r| r.lrem "queue:app_queue", -1, "the payload string stored in Redis" }
您可以通过redis-cli
以下方法更轻松地完成所有这些操作:
$ redis-cli
> select 0 # (or whichever namespace Sidekiq is using)
> keys * # (just to get an idea of what you're working with)
> smembers queues
> lrange queues:app_queue 0 -1
> lrem queues:app_queue -1 "payload"
Sidekiq::Client.registered_queues
已被替换Sidekiq::Queue.all
和Sidekiq::Client.registered_workers
用Sidekiq::Workers.new
,请参阅:github.com/mperham/sidekiq/blob/...
有一个符合人体工程学的API,用于查看和管理队列。
默认情况下不是必需的。
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
是否有计划的工作。您可以使用以下命令删除所有作业:
Sidekiq::ScheduledSet.new.clear
如果有任何队列要删除所有作业,则可以使用以下命令:
Sidekiq::Queue.new.clear
重试作业也可以通过以下命令删除:
Sidekiq::RetrySet.new.clear
在以下链接中有更多信息,您可以结帐:https : //github.com/mperham/sidekiq/wiki/API
有一个API用于访问有关工作程序,队列和作业的实时信息。
请访问此处https://github.com/mperham/sidekiq/wiki/API
默认队列中有绞死的“工人”,我可以通过Web界面看到他们。但是,如果我使用Sidekiq :: Queue.new.size,则无法从控制台使用它们
irb(main):002:0> Sidekiq::Queue.new.size
2014-03-04T14:37:43Z 17256 TID-oujb9c974 INFO: Sidekiq client with redis options {:namespace=>"sidekiq_staging"}
=> 0
使用redis-cli我可以找到它们
redis 127.0.0.1:6379> keys *
1) "sidekiq_staging:worker:ip-xxx-xxx-xxx-xxx:7635c39a29d7b255b564970bea51c026-69853672483440:default"
2) "sidekiq_staging:worker:ip-xxx-xxx-xxx-xxx:0cf585f5e93e1850eee1ae4613a08e45-70328697677500:default:started"
3) "sidekiq_staging:worker:ip-xxx-xxx-xxx-xxx:7635c39a29d7b255b564970bea51c026-69853672320140:default:started"
...
解决方案是:
irb(main):003:0> Sidekiq.redis { |r| r.del "workers", 0, -1 }
=> 1
在Sidekiq v3中也有一个命令
Sidekiq::Workers.new.prune
但是由于某种原因,那天那天它对我不起作用
如果要清除sidekiq重试队列,就是这样: Sidekiq::RetrySet.new.clear
$ redis-cli
> select 0 # (or whichever namespace Sidekiq is using)
> keys * # (just to get an idea of what you're working with)
> smembers queues
> lrange queue:queue_name 0 -1 # (queue_name must be your relevant queue)
> lrem queue:queue_name -1 "payload"
keys *
除非将Redis仅用于sidekiq,否则切勿在生产环境中运行。如果您有大量数据集(缓存等),则尤其不要运行它。Redis是单线程的,并且会keys *
阻塞-这可能导致大型数据集(几个Gbs)停机几分钟。