add tasks / job to migrate pjs under namespace
This commit is contained in:
parent
7ce7a3f62c
commit
9fa864448e
2 changed files with 56 additions and 0 deletions
25
lib/tasks/pjs.rake
Normal file
25
lib/tasks/pjs.rake
Normal file
|
@ -0,0 +1,25 @@
|
|||
namespace :pjs do
|
||||
task stats: :environment do
|
||||
end
|
||||
|
||||
desc <<~EOD
|
||||
bin/rake 'pjs:migrate['aa']'
|
||||
bin/rake 'pjs:migrate['aa-ab-ac']'
|
||||
EOD
|
||||
task :migrate, [:prefixes] => :environment do |_t, args|
|
||||
# [a-b] => "key LIKE 'a%' or key LIKE 'b%'"
|
||||
prefix_like_query = args[:prefixes]
|
||||
.split('-')
|
||||
.map { "key LIKE '#{_1}%'" }
|
||||
.join(' or ')
|
||||
|
||||
blobs = ActiveStorage::Blob
|
||||
.where(prefix_like_query)
|
||||
.where.not("key LIKE '%/%'") # do not touch already moved blob
|
||||
|
||||
blobs_count = blobs.count
|
||||
rake_puts "targeted prefix: #{args[:prefixes]}, #{blobs_count} blobs"
|
||||
|
||||
blobs.in_batches { |batch| batch.ids.each { |id| PjsMigrationJob.perform_later(id) } }
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue