Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a script to stop spurious delete jobs #3917

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions script/stop_delete_jobs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# frozen_string_literal: true

require 'progress_counter'

# Run like this multiple times as new jobs can be scheduled while running
# bundle exec rails runner script/stop_delete_jobs.rb Hierarchy-Service-2555417726785

# e.g. "Hierarchy-Service-2555417734629"
ROOT_OBJECT_TO_DELETE = ARGV.shift
QUEUES = %w[default deletion].freeze

def each_with_progress_counter(enumerable, count)
progress = ProgressCounter.new(count)
enumerable.each do |element|
yield element
progress.call
end
end

def job_matches_conditions(job)
return false unless job.item && job.item["args"].is_a?(Array)

first_arg = job.item["args"].first
!first_arg.is_a?(Numeric) &&
%w[DeleteObjectHierarchyWorker DeleteAccountHierarchyWorker DeletePlainObjectWorker].include?(first_arg["job_class"]) &&
first_arg["arguments"].is_a?(Array) &&
first_arg["arguments"][1] && first_arg["arguments"][1].include?(ROOT_OBJECT_TO_DELETE)
end

def delete_from_queue(queue_name)
queue = Sidekiq::Queue.new(queue_name)
puts "Deleting from queue '#{queue_name}'..."
count = 0

each_with_progress_counter(queue, queue.size) do |job|
next unless job_matches_conditions(job)

# pp job.item["args"]
job.delete
count += 1
# puts '------------------------------------------------------------'
end
puts "#{count} jobs deleted from queue '#{queue_name}'!"
end

def delete_from_scheduled
ss = Sidekiq::ScheduledSet.new
puts "Deleting from scheduled set..."
count = 0
each_with_progress_counter(ss, ss.size) do |job|
next unless job_matches_conditions(job)

# pp job.item["args"]
job.delete
count += 1
# puts '------------------------------------------------------------'
end
puts "#{count} jobs deleted from scheduled set!"
end

delete_from_scheduled

QUEUES.each { delete_from_queue(_1) }