Last active
June 5, 2017 14:09
-
-
Save AlxGolubev/8d8c7f0db64ed6e4232fde79c833fe19 to your computer and use it in GitHub Desktop.
Class for case when queue for worker was changed but there are a lot of scheduled jobs in queue previously used
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JobsMover | |
BATCH_SIZE = 100 | |
def initialize(original_queue, klass) | |
@original_queue = Sidekiq::Queue.new(original_queue) | |
@klass = klass | |
end | |
def move | |
jobs = @original_queue.select { |job| job.item['class'] == @klass } | |
total = jobs.count | |
progress = 0 | |
jobs.each_slice(BATCH_SIZE) do |jobs_set| | |
jobs_set.each do |job| | |
job.delete | |
@klass.constantize.perform_async(*job.item['args']) | |
end | |
print "#{progress += BATCH_SIZE} / #{total} \r" | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JobsRemover | |
BATCH_SIZE = 100 | |
def initialize(original_queue, klass) | |
@original_queue = Sidekiq::Queue.new(original_queue) | |
@klass = klass | |
end | |
def remove | |
jobs = @original_queue.select { |job| job.item['class'] == @klass } | |
total = jobs.count | |
progress = 0 | |
jobs.each_slice(BATCH_SIZE) do |jobs_set| | |
jobs_set.each do |job| | |
job.delete | |
end | |
print "#{progress += BATCH_SIZE} / #{total} \r" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/mperham/sidekiq/wiki/FAQ#how-do-i-cancel-a-sidekiq-job