diff --git a/README.md b/README.md index 6a55aac..f7bceea 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Manage and continuously rebuild your ElasticSearch indexes with [Chewy](https://github.com/toptal/chewy/) and [Capistrano](https://github.com/capistrano/capistrano) v3. -`Capistrano::Chewy` gem adds automatic conditionally reset only modified Chewy indexes to your deploy flow so you do not have to build them manually. +`Capistrano::Chewy` gem adds automatic conditionally reset of only modified Chewy indexes and the removal of deleted index files to your deploy flow so you do not have to do it manually. Moreover, it adds the possibility of manual index management with the base Chewy tasks on the remote server. ## Requirements @@ -51,7 +51,9 @@ Require it in your `Capfile`: ```ruby # Capfile +... require 'capistrano/chewy' +... ``` then you can use `cap -T` to list `Capistrano::Chewy` tasks: @@ -64,7 +66,7 @@ cap deploy:chewy:update # Updates data to all the indexes cap deploy:chewy:update[indexes] # Updates data to the specified indexes ``` -By default `Capistrano::Chewy` adds `deploy:chewy:rebuild` task after `deploy:updated` and `deploy:chewy:rollback_indexes` after `deploy:reverted`. +By default `Capistrano::Chewy` adds `deploy:chewy:rebuild` task after `deploy:updated` and `deploy:reverted`. If you want to change it, then you need to disable default gem hooks by setting `chewy_default_hooks` to `false` in your deployment config and manually define the order of the tasks. ## Configuration @@ -78,7 +80,7 @@ set :chewy_path, 'app/my_indexes' # Path to Chewy indexes, 'app/chewy' by defaul set :chewy_env, :chewy_production # Environment variable for Chewy, equal to RAILS_ENV by default set :chewy_role, :web # Chewy role, :app by default set :chewy_default_hooks, false # Add default capistrano-chewy hooks to your deploy flow, true by default -set :chewy_delete_removed_indexes, false # Delete indexes which have been removed +set :chewy_delete_removed_indexes, false # Delete indexes which files have been deleted, true by default ``` ## Contributing diff --git a/capistrano3-postgres.gemspec b/capistrano-chewy.gemspec similarity index 92% rename from capistrano3-postgres.gemspec rename to capistrano-chewy.gemspec index 1d6a4c8..a26c1a3 100644 --- a/capistrano3-postgres.gemspec +++ b/capistrano-chewy.gemspec @@ -7,8 +7,8 @@ Gem::Specification.new do |spec| spec.name = 'capistrano-chewy' spec.version = CapistranoChewy.gem_version spec.authors = ['Nikita Bulai'] - spec.date = '2016-10-18' - spec.email = ['bulainikita@gmail.com'] + spec.date = '2016-10-19' + spec.email = ['bulajnikita@gmail.com'] spec.summary = 'Manage and continuously rebuild your ElasticSearch indexes with Chewy and Capistrano' spec.description = 'Manage and continuously rebuild your ElasticSearch indexes with Chewy and Capistrano v3.' spec.homepage = 'https://github.com/nbulaj/capistrano-chewy' diff --git a/lib/capistrano-chewy/diff_parser.rb b/lib/capistrano-chewy/diff_parser.rb index 5e441e1..06a1440 100644 --- a/lib/capistrano-chewy/diff_parser.rb +++ b/lib/capistrano-chewy/diff_parser.rb @@ -19,7 +19,7 @@ def empty? class << self def parse(diff, current_path, release_path) - raise ArgumentError, 'current_path can not be the same as release_path!' if current_path == release_path + return Result.new if current_path == release_path diff.split("\n").each_with_object(Result.new) do |line, result| # File was changed diff --git a/lib/capistrano-chewy/version.rb b/lib/capistrano-chewy/version.rb index 45a3f9c..b9de4d0 100644 --- a/lib/capistrano-chewy/version.rb +++ b/lib/capistrano-chewy/version.rb @@ -5,7 +5,7 @@ def self.gem_version module VERSION MAJOR = 0 - MINOR = 1 + MINOR = 2 TINY = 0 STRING = [MAJOR, MINOR, TINY].compact.join('.') diff --git a/lib/capistrano/tasks/chewy.rake b/lib/capistrano/tasks/chewy.rake index 498bd05..a7b9237 100644 --- a/lib/capistrano/tasks/chewy.rake +++ b/lib/capistrano/tasks/chewy.rake @@ -14,14 +14,11 @@ namespace :deploy do invoke :'deploy:chewy:add_default_hooks' if fetch(:chewy_default_hooks) end - after :reverted, :rollback_chewy_indexes do - invoke :'deploy:chewy:rollback_indexes' if fetch(:chewy_default_hooks) - end - namespace :chewy do # Adds default Capistrano::Chewy hooks to the deploy flow task :add_default_hooks do - after 'deploy:updated', 'deploy:chewy:rebuild' + after :'deploy:updated', 'deploy:chewy:rebuild' + after :'deploy:reverted', 'deploy:chewy:rebuild' end # Default Chewy rake tasks @@ -60,11 +57,6 @@ namespace :deploy do end end - desc 'Rollback indexes on deployment rollback' - task :rollback_indexes do - # TODO - end - # Smart rebuild of modified Chewy indexes desc 'Reset Chewy indexes if they have been added, changed or removed' task :rebuild do @@ -132,13 +124,13 @@ namespace :deploy do # Delete indexes which have been removed if indexes_to_delete.any? && fetch(:chewy_delete_removed_indexes) - indexes = indexes_to_delete.map { |file| File.basename(file, '.rb').camelize } - runner_code = indexes.map { |index| "#{index}.delete"}.join("\n") + indexes = indexes_to_delete.map { |file| File.basename(file, '.rb').camelize }.uniq + runner_code = "[#{indexes.join(', ')}].each(&:delete)" # Removed index files exists only in the old (current) release within current_path do with rails_env: fetch(:chewy_env) do - info "Indexes to remove: #{indexes.join(',')}" + info "Removing indexes: #{indexes.join(',')}" execute :rails, "runner '#{runner_code}'" end end diff --git a/spec/diff_parser_spec.rb b/spec/diff_parser_spec.rb index 0f4a113..a6ebed8 100644 --- a/spec/diff_parser_spec.rb +++ b/spec/diff_parser_spec.rb @@ -39,8 +39,14 @@ end context 'with the same directories' do - it 'raises an error' do - expect { described_class.parse('', current_path, current_path) }.to raise_error(ArgumentError) + it 'returns blank result' do + result = described_class.parse('', current_path, current_path) + + expect(result.changed).to be_empty + expect(result.added).to be_empty + expect(result.removed).to be_empty + + expect(result.empty?).to be_truthy end end end