Last active
August 7, 2020 20:49
-
-
Save nik-holo/199e2f491d67fd45a32519c253454be6 to your computer and use it in GitHub Desktop.
update_tasks.rb
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
puts 'Started updating tasks parents' | |
started_at = Time.now | |
updated = 0 | |
updated_task_ids = [] | |
relation = ::Task.where(guide_guid: 'reply_to_message') | |
tasks_count = relation.count | |
puts "tasks to update #{tasks_count}" | |
relation.find_each(batch_size: 100) do |task| | |
if task.parent_guid.present? | |
begin | |
old_parent = task[:parent_guid] | |
message = ::Messages::Base.find_by(guid: old_parent) | |
task.parent_guid = message.message_thread_guid if message | |
task.save! | |
puts "#{message.message_thread_guid} is new GUID of MT" if message | |
puts "=== Task ##{task.id} updated parent_guid: from #{old_parent} to: #{task.parent_guid}" | |
rescue StandardError => error | |
puts error | |
puts "Message with: #{task.parent_guid} guid not found. Assuming its a MT_guid" | |
end | |
updated = updated + 1 | |
updated_task_ids << task.id | |
puts "=== Updated [#{updated} / #{tasks_count}]" | |
end | |
end | |
ended_at = Time.now | |
puts '=== Done' | |
puts "=== Updated #{updated_task_ids.size} of #{tasks_count}" | |
puts "=== Finished in #{ended_at-started_at} seconds" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment