Ruby-on-rails 如何从sidekiq清除所有作业?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24886371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to clear all the jobs from sidekiq?
提问by Can Can
I am using sidekiq for background tasks in Rails application. Now the numbers of jobs becomes more, so I want to clear all the jobs. I tried the following command in console
我在 Rails 应用程序中使用 sidekiq 进行后台任务。现在工作的数量变得更多,所以我想清除所有的工作。我在控制台中尝试了以下命令
Sidekiq::Queue.new.clear
but it was giving following error.
但它给出了以下错误。
NameError: uninitialized constant Sidekiq::Queue
How do I clear all the jobs from sidekiq?
如何从 sidekiq 清除所有作业?
采纳答案by Jay
According to this issue on Github: https://github.com/mperham/sidekiq/issues/1732you now need to
根据 Github 上的这个问题:https: //github.com/mperham/sidekiq/issues/1732你现在需要
require 'sidekiq/api'
回答by jonathanccalixto
You can do as it says on the issue 1077or as reported in this blog at noobsippets
您可以按照问题 1077 上的说明或在 noobsippets 的此博客中报告的那样进行操作
Both suggest we do the following, and can be done on rails console:
两者都建议我们执行以下操作,并且可以在 rails 控制台上完成:
Sidekiq.redis { |conn| conn.flushdb }
Sidekiq.redis { |conn| conn.flushdb }
回答by rusllonrails
Clear Sidekiq Jobs commands:
清除 Sidekiq 作业命令:
require 'sidekiq/api'
# Clear retry set
Sidekiq::RetrySet.new.clear
# Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear
# Clear 'Dead' jobs statistics
Sidekiq::DeadSet.new.clear
# Clear 'Processed' and 'Failed' jobs statistics
Sidekiq::Stats.new.reset
# Clear specific queue
stats = Sidekiq::Stats.new
stats.queues
# => {"main_queue"=>25, "my_custom_queue"=>1}
queue = Sidekiq::Queue.new('my_custom_queue')
queue.count
queue.clear
回答by Xavier
As of latest Sidekiq, just blow it up:
截至最新的 Sidekiq,只需将其炸毁:
require 'sidekiq/api'
q = Sidekiq::Queue.new
q.
Yes, the command to clear all is literally a bomb emoji. Also works for Sidekiq::RetrySet.
是的,清除所有命令实际上是一个炸弹表情符号。也适用于Sidekiq::RetrySet.
Or if you're no fun you can use q.clear
或者如果你不好玩,你可以使用 q.clear
回答by Sai Ram Reddy
redis-cli flushdb
You can also use redis-cli flushall
你也可以使用 redis-cli flushall
回答by fangxing
Use Rails runner in one line
在一行中使用 Rails runner
rails runner 'Sidekiq.redis { |conn| conn.flushdb }'
回答by Andriy Kondzolko
All Sidekiq tasks are saved in "Redis".
所有 Sidekiq 任务都保存在“Redis”中。
You can clean "Redis" by this command
您可以通过此命令清理“Redis”
redis-cli flushall
回答by Ravi Prakash Singh
You can use this for clearing all the jobs
您可以使用它来清除所有作业
require 'sidekiq/api'
Sidekiq::Queue.all.each(&:clear)
回答by Nicolás Schmidt Gubbins
require 'sidekiq/api'
Sidekiq::Queue.all.each {|x| x.clear}
回答by shashwat srivastava
If you want to delete jobs from specific queues try:
如果要从特定队列中删除作业,请尝试:
queue = Sidekiq::Queue.new("default")
queue.each do |job|
job.klass # => 'TestWorker'
job.args # => ['easy']
job.delete if job.jid == 'abcdef1234567890' || job.klass == 'TestWorker'
end
Read all about sidekiq and important console commands- https://medium.com/@shashwat12june/all-you-need-to-know-about-sidekiq-a4b770a71f8f
阅读有关 sidekiq 和重要控制台命令的所有信息 - https://medium.com/@shashwat12june/all-you-need-to-know-about-sidekiq-a4b770a71f8f

