Skip to content

Instantly share code, notes, and snippets.

@golodenko
Last active November 9, 2020 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save golodenko/b42ab1205674657e299d2c59cf6454ae to your computer and use it in GitHub Desktop.
Save golodenko/b42ab1205674657e299d2c59cf6454ae to your computer and use it in GitHub Desktop.
checking_tasks_mt.rb
failed_tasks = []
failed_tasks_by_ref = []
task_ids = [329136, 538046, 538356, 26390, 132307, 499667, 53154, 73316, 87621, 611359, 657803, 457885, 554784, 607724, 629694, 663473, 127289, 130200, 298003, 488789, 50716, 272952, 27791, 71771, 71869, 71872, 72035, 72041, 85363, 722455, 54784]
task_ids.each do |task_id|
task = ::Task.find(task_id)
puts "no task found wih #{task_id}" if task.blank?
failed_tasks << task_id if task.blank? || task.initial_message["complaint_id"].blank?
puts "no complaint_id for task ##{task.id}" if task.initial_message["complaint_id"].blank?
next if task.initial_message["complaint_id"].blank?
puts "Initial message complaint id: #{task.initial_message['complaint_id']}"
begin
complaint = ::Db::Complaint.find_by!(id: task.initial_message["complaint_id"])
if complaint.present?
task.complaint_reference = complaint.reference
puts "complaint.reference: #{complaint.reference}"
task.save!
puts "task.complaint_reference: #{task.complaint_reference}"
failed_tasks_by_ref << task_id if complaint.reference.blank?
puts "complaint with guid: #{complaint.id} found, saving task and moving on"
end
rescue
failed_tasks << task_id
puts "=== CHECK_ERROR complaint not found!"
end
end
puts "Failed number: #{failed_tasks.count.to_s} of #{task_ids.count.to_s}"
puts "Failed for no complaint assigned: #{failed_tasks.to_s}"
puts "Failed number: #{failed_tasks_by_ref.count.to_s} of #{task_ids.count.to_s}"
puts "Failed for no complaint assigned: #{failed_tasks_by_ref.to_s}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment