zelastic 0.3.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b20a3c4e66ac288594edfc999f4499ce50c5f0c
4
- data.tar.gz: caacc8874bc47d4fa812fdadc06c0795ad732c73
3
+ metadata.gz: 05b9d19442778ad53fe696cbcf6d202b9216cd53
4
+ data.tar.gz: 3e8e17c98cc6ee0332449e232c7de492dc94f79e
5
5
  SHA512:
6
- metadata.gz: 9a09f4b7bc7298a98d99a78345207b0a3cf9ff8855e8ca5b615d4f5f04e21c3495988e4e7a4100e8e1a125c85f5d64cc4b606c07b82ea222eff736d757c0c235
7
- data.tar.gz: 8f2fef61bcb084ac942b23fecc6c9dff60fe198dca81387be8b6a0a9e880f2687fd1ae44224c389f4353c652a727d9ae31f6f551a06b0a34cc0888474937cae0
6
+ metadata.gz: a7186c7a3dd66d97bc7567e33023742c2fda9718846d8e58c2bbe9c17ef18055858e7e5fb0b600d3629b365c300350e6b694068368a40599ccaf9be41c931d74
7
+ data.tar.gz: bd24900db1022ef69a0a457c03f50e3e2a1ec884e4eba60ddd2084a3555ba0e9921a99b39293dacc1436ebcf441de40eab8184f4269229c93127990dbe2a46e2
data/.circleci/config.yml CHANGED
@@ -1,8 +1,11 @@
1
- ruby: &ruby
2
- image: carwow/ruby-ci:2.4.3
1
+ references:
2
+ ruby: &ruby
3
+ image: carwow/ruby-ci:2.4.4
4
+ environment:
5
+ ELASTICSEARCH_URL: http://localhost:9200
3
6
 
4
- elasticsearch_container: &elasticsearch_container
5
- image: carwow/elasticsearch-ci:5.5.1
7
+ elasticsearch_container: &elasticsearch_container
8
+ image: carwow/elasticsearch-ci:5.5.1
6
9
 
7
10
  version: 2
8
11
  jobs:
@@ -30,7 +33,7 @@ jobs:
30
33
  - *ruby
31
34
  steps:
32
35
  - checkout
33
- - restore_cache: { keys: ['bundle-{{ checkout "Gemfile.lock" }}'] }
36
+ - restore_cache: { keys: ['bundle-{{ checksum "Gemfile.lock" }}'] }
34
37
  - run: bundle exec rubocop
35
38
 
36
39
  tests:
@@ -40,9 +43,17 @@ jobs:
40
43
  - *elasticsearch_container
41
44
  steps:
42
45
  - checkout
43
- - restore_cache: { keys: ['bundle-{{ checkout "Gemfile.lock" }}'] }
46
+ - restore_cache: { keys: ['bundle-{{ checksum "Gemfile.lock" }}'] }
47
+ - run:
48
+ name: Wait for ES to be ready
49
+ command: |
50
+ until curl $ELASTICSEARCH_URL/_cat/health | egrep '(green|yellow)' 2>&1 > /dev/null; do
51
+ echo -n .
52
+ sleep 1
53
+ done
44
54
  - run: |
45
55
  bundle exec rspec --pattern "**/*_spec.rb" --format "progress"
56
+
46
57
  workflows:
47
58
  version: 2
48
59
  build:
data/.rubocop.yml CHANGED
@@ -1,3 +1,5 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
1
3
  AllCops:
2
4
  TargetRubyVersion: 2.4
3
5
 
@@ -5,6 +7,7 @@ AllCops:
5
7
  Metrics/BlockLength:
6
8
  Exclude:
7
9
  - '*.gemspec'
10
+ - 'spec/**/*'
8
11
 
9
12
  # Configuration parameters: CountComments.
10
13
  Metrics/MethodLength:
@@ -18,4 +21,4 @@ Style/Documentation:
18
21
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
19
22
  # URISchemes: http, https
20
23
  Metrics/LineLength:
21
- Max: 102
24
+ Max: 100
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,32 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-05-27 17:11:31 +0100 using RuboCop version 0.52.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Lint/ShadowingOuterLocalVariable:
11
+ Exclude:
12
+ - 'lib/zelastic/indexer.rb'
13
+
14
+ # Offense count: 1
15
+ Metrics/AbcSize:
16
+ Max: 17
17
+
18
+ # Offense count: 1
19
+ # Configuration parameters: CountComments, ExcludedMethods.
20
+ Metrics/BlockLength:
21
+ Max: 83
22
+
23
+ # Offense count: 4
24
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
25
+ # URISchemes: http, https
26
+ Metrics/LineLength:
27
+ Max: 146
28
+
29
+ # Offense count: 1
30
+ Naming/AccessorMethodName:
31
+ Exclude:
32
+ - 'spec/zelastic/indexer_spec.rb'
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ v0.4.0 - May 29th, 2018
2
+ ---
3
+
4
+ - Warning rather than exception on ignorable version conflicts (#4)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zelastic (0.3.4)
4
+ zelastic (0.4.0)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -23,10 +23,22 @@ GEM
23
23
  coderay (1.1.2)
24
24
  concurrent-ruby (1.0.5)
25
25
  diff-lcs (1.3)
26
+ elasticsearch (6.0.2)
27
+ elasticsearch-api (= 6.0.2)
28
+ elasticsearch-transport (= 6.0.2)
29
+ elasticsearch-api (6.0.2)
30
+ multi_json
31
+ elasticsearch-transport (6.0.2)
32
+ faraday
33
+ multi_json
34
+ faraday (0.15.2)
35
+ multipart-post (>= 1.2, < 3)
26
36
  i18n (0.9.1)
27
37
  concurrent-ruby (~> 1.0)
28
38
  method_source (0.9.0)
29
39
  minitest (5.11.1)
40
+ multi_json (1.13.1)
41
+ multipart-post (2.0.0)
30
42
  parallel (1.12.1)
31
43
  parser (2.4.0.2)
32
44
  ast (~> 2.3)
@@ -68,6 +80,7 @@ PLATFORMS
68
80
  DEPENDENCIES
69
81
  activerecord
70
82
  bundler
83
+ elasticsearch
71
84
  pry
72
85
  rake
73
86
  rspec
@@ -75,4 +88,4 @@ DEPENDENCIES
75
88
  zelastic!
76
89
 
77
90
  BUNDLED WITH
78
- 1.16.1
91
+ 1.16.2
@@ -91,7 +91,9 @@ module Zelastic
91
91
  logger.info('Nothing to do: no old indices')
92
92
  return
93
93
  end
94
- logger.info("Deleting #{indices_to_delete.count} old indices: #{indices_to_delete.join(', ')}")
94
+ logger.info(
95
+ "Deleting #{indices_to_delete.count} old indices: #{indices_to_delete.join(', ')}"
96
+ )
95
97
  client.indices.delete(index: indices_to_delete)
96
98
  end
97
99
  # rubocop:enable Metrics/AbcSize
@@ -5,10 +5,8 @@ module Zelastic
5
5
  class IndexingError < StandardError
6
6
  attr_reader :errors
7
7
 
8
- def initialize(result)
9
- @errors = result['items'].map do |item|
10
- item['error'] || item.fetch('index', {})['error']
11
- end.compact
8
+ def initialize(errors)
9
+ @errors = errors
12
10
  super("Errors indexing: #{errors.join(', ')}")
13
11
  end
14
12
  end
@@ -103,9 +101,33 @@ module Zelastic
103
101
  commands = indices.flat_map { |index| yield(index) }
104
102
 
105
103
  current_client.bulk(body: commands).tap do |result|
106
- raise IndexingError, result if result['errors']
104
+ check_errors!(result)
107
105
  end
108
106
  end
109
107
  end
108
+
109
+ def check_errors!(result)
110
+ return false unless result['errors']
111
+
112
+ errors = result['items']
113
+ .map { |item| item['error'] || item.fetch('index', {})['error'] }
114
+ .compact
115
+
116
+ ignorable_errors, important_errors = errors
117
+ .partition { |error| ignorable_error?(error) }
118
+
119
+ logger.warn("Ignoring #{ignorable_errors.count} version conflicts") if ignorable_errors.any?
120
+
121
+ return unless important_errors.any?
122
+ raise IndexingError, important_errors
123
+ end
124
+
125
+ def ignorable_error?(error)
126
+ # rubocop:disable Metrics/LineLength
127
+ regexp = /^\[#{config.type}\]\[\d+\]: version conflict, current version \[\d+\] is higher or equal to the one provided \[\d+\]$/
128
+ # rubocop:enable Metrics/LineLength
129
+ error['type'] == 'version_conflict_engine_exception' &&
130
+ error['reason'] =~ regexp
131
+ end
110
132
  end
111
133
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zelastic
4
- VERSION = '0.3.4'
4
+ VERSION = '0.4.0'
5
5
  end
data/zelastic.gemspec CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
27
27
 
28
28
  spec.add_development_dependency 'activerecord'
29
29
  spec.add_development_dependency 'bundler'
30
+ spec.add_development_dependency 'elasticsearch'
30
31
  spec.add_development_dependency 'pry'
31
32
  spec.add_development_dependency 'rake'
32
33
  spec.add_development_dependency 'rspec'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zelastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - carwow Developers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-22 00:00:00.000000000 Z
11
+ date: 2018-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: elasticsearch
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: pry
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -119,6 +133,8 @@ files:
119
133
  - ".gitignore"
120
134
  - ".rspec"
121
135
  - ".rubocop.yml"
136
+ - ".rubocop_todo.yml"
137
+ - CHANGELOG.md
122
138
  - Gemfile
123
139
  - Gemfile.lock
124
140
  - LICENSE.txt
@@ -152,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
168
  version: '0'
153
169
  requirements: []
154
170
  rubyforge_project:
155
- rubygems_version: 2.5.2
171
+ rubygems_version: 2.6.14.1
156
172
  signing_key:
157
173
  specification_version: 4
158
174
  summary: Zero-downtime (re-)indexing of ActiveRecord models into Elasticsearch.