Skip to content

Commit

Permalink
Delete of removed indexes, README update, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nbulaj committed Oct 19, 2016
1 parent 008ebaa commit e9aff7e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions capistrano3-postgres.gemspec → capistrano-chewy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion lib/capistrano-chewy/diff_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/capistrano-chewy/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def self.gem_version

module VERSION
MAJOR = 0
MINOR = 1
MINOR = 2
TINY = 0

STRING = [MAJOR, MINOR, TINY].compact.join('.')
Expand Down
18 changes: 5 additions & 13 deletions lib/capistrano/tasks/chewy.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions spec/diff_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e9aff7e

Please sign in to comment.