Skip to content

Commit

Permalink
Enhance/rake tasks force suffix (#1)
Browse files Browse the repository at this point in the history
Co-authored-by: dsantosmerino <dsantosmerino@gmail.com>
  • Loading branch information
oricodes89 and dsantosmerino committed Jul 2, 2021
1 parent 8967c24 commit 4b259cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
9 changes: 5 additions & 4 deletions lib/chewy/rake_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def reset(only: nil, except: nil, parallel: nil, output: STDOUT)
# @param parallel [true, Integer, Hash] any acceptable parallel options for import
# @param output [IO] output io for logging
# @return [Array<Chewy::Index>] indexes that were actually reset
def upgrade(only: nil, except: nil, parallel: nil, output: STDOUT)
def upgrade(only: nil, except: nil, parallel: nil, output: STDOUT, force_suffix: nil)
subscribed_task_stats(output) do
indexes = indexes_from(only: only, except: except)

Expand All @@ -70,7 +70,7 @@ def upgrade(only: nil, except: nil, parallel: nil, output: STDOUT)
if changed_indexes.present?
indexes.each do |index|
if changed_indexes.include?(index)
reset_one(index, output, parallel: parallel)
reset_one(index, output, parallel: parallel, force_suffix: force_suffix)
else
output.puts "Skipping #{index}, the specification didn't change"
end
Expand Down Expand Up @@ -294,9 +294,10 @@ def human_duration(seconds)
end.compact.reverse.join(' ')
end

def reset_one(index, output, parallel: false)
def reset_one(index, output, parallel: false, force_suffix: nil)
output.puts "Resetting #{index}"
index.reset!((Time.now.to_f * 1000).round, parallel: parallel)
suffix = force_suffix || (Time.now.to_f * 1000).round
index.reset!(suffix, parallel: parallel)
end
end
end
Expand Down
15 changes: 10 additions & 5 deletions lib/tasks/chewy.rake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace :chewy do

desc 'Resets data for the specified indexes or all of them only if the index specification is changed'
task upgrade: :environment do |_task, args|
Chewy::RakeHelper.upgrade(parse_classes(args.extras))
force_suffix = args.extras.first
Chewy::RakeHelper.upgrade(force_suffix: force_suffix)
end

desc 'Updates data for the specified indexes/types or all of them'
Expand All @@ -42,8 +43,9 @@ namespace :chewy do
end

desc 'Resets all the indexes with the specification changed and synchronizes the rest of them'
task deploy: :environment do
processed = Chewy::RakeHelper.upgrade
task deploy: :environment do |_task, args|
force_suffix = args.extras.first
processed = Chewy::RakeHelper.upgrade(force_suffix: force_suffix)
Chewy::RakeHelper.sync(except: processed)
end

Expand All @@ -55,7 +57,9 @@ namespace :chewy do

desc 'Parallel version of `rake chewy:upgrade`'
task upgrade: :environment do |_task, args|
Chewy::RakeHelper.upgrade(parse_parallel_args(args.extras))
parallel = args.extras.first =~ /\A\d+\z/ ? Integer(args.extras.first) : true
force_suffix = args.extras.second
Chewy::RakeHelper.upgrade(parallel: parallel, force_suffix: force_suffix)
end

desc 'Parallel version of `rake chewy:update`'
Expand All @@ -71,7 +75,8 @@ namespace :chewy do
desc 'Parallel version of `rake chewy:deploy`'
task deploy: :environment do |_task, args|
parallel = args.extras.first =~ /\A\d+\z/ ? Integer(args.extras.first) : true
processed = Chewy::RakeHelper.upgrade(parallel: parallel)
force_suffix = args.extras.second
processed = Chewy::RakeHelper.upgrade(parallel: parallel, force_suffix: force_suffix)
Chewy::RakeHelper.sync(except: processed, parallel: parallel)
end
end
Expand Down

0 comments on commit 4b259cb

Please sign in to comment.