Skip to content

Instantly share code, notes, and snippets.

@pnispel
Last active October 26, 2017 20:20
Show Gist options
  • Save pnispel/e8bab097a98fee3e5cd609875afca2eb to your computer and use it in GitHub Desktop.
Save pnispel/e8bab097a98fee3e5cd609875afca2eb to your computer and use it in GitHub Desktop.
pft
module StorageProfileKey
# This class backfills storage_profile_key on prostore_file_thumbnails.
# Once the backfill completes and there is a not null constraint
# and default value on the column, this class can be removed.
class ProstoreFileThumbnailsBackfillWorker
include Sidekiq::Worker
sidekiq_options queue: :data_migration
def self.enqueue_prostore_file_thumbnails(starting_id:, ending_id:)
ProstoreFileThumbnail.select(:id).where(id: starting_id..ending_id).find_each do |prostore_file_thumbnail|
perform_async(prostore_file_thumbnail.id)
end
end
def perform(prostore_file_thumbnail_id)
prostore_file_thumbnail = ProstoreFileThumbnail.find(prostore_file_thumbnail_id)
storage_profile_key = prostore_file_thumbnail&.prostore_file.storage_profile_key || Company.default_s3_profile_name
prostore_file_thumbnail.update_column(storage_profile_key: storage_profile_key)
end
end
end
@pnispel
Copy link
Author

pnispel commented Oct 26, 2017

find_each uses the same default as find_in_batches http://api.rubyonrails.org/classes/ActiveRecord/Batches.html#method-i-find_each I can change that batch_size to 100 though if we think thats more sane.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment