active_record_streams 0.1.3 → 0.1.4

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
  SHA256:
3
- metadata.gz: db02bce16951d859a2430c95d561322091feeb07a388d348e31b3a44ba42ddfb
4
- data.tar.gz: 2ff33c6f3046974f161d94ded9eb6fac1bbf1f66a107c47c4341d88e909d53eb
3
+ metadata.gz: 55ce8ad67b9fb07fe31af17d43d354cedaa806eb1ee2256af3267396d509f946
4
+ data.tar.gz: 47247a17b827034a7e2402acce13b1bb01da23b95b24bbcaf61cb567bcd2196a
5
5
  SHA512:
6
- metadata.gz: 2accfc57874c853d364c272a74dbe47a26a764071676fcdb022166f11dc6ec7d1c0fba9205f9e2ca27e49e95d372fcdb128656360d044ff9f873f5103911a9a2
7
- data.tar.gz: 2a2dfdb5341d1744389f82014671284e602e351822210f873cb230881e5288a71f9ff26759c816439eaf9137fc25bf76a69a8974114d9d743d8122862c5b9da0
6
+ metadata.gz: d0f83bbbb70f7ccd09d0e771c5815dfbd5dd63a13730fd29a254b60696bcae66026445ce90cbccd462e1c7d7b5186059222f172e57109de3ce0f77ff5e0ff67d
7
+ data.tar.gz: 6bc49e902ab3a51bdcd2aff33e7e8523843d816e7014c35dc7f88b4dd2961526e46cf02d63d41b40a3b619d6b158ce6fa3074fb5bc14a4c43dba6287cc17b9d0
data/CHANGELOG.md CHANGED
@@ -26,3 +26,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
26
26
  ## [0.1.3] - 2019-05-02
27
27
  ### Changed
28
28
  - `Content-type` header for the HTTP streams is set as a string to fix doubled content-type issue
29
+
30
+ ## [0.1.4] - 2019-05-02
31
+ ### Added
32
+ - Error-handler switch for `publish` methods
33
+
34
+ ### Changed
35
+ - README to reflect the error-handler switch
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_record_streams (0.1.3)
4
+ active_record_streams (0.1.4)
5
5
  activerecord (~> 4.2.10)
6
6
  aws-sdk (~> 2.11.9)
7
7
 
data/README.md CHANGED
@@ -134,7 +134,10 @@ class SampleHttpReSender
134
134
  def perform(table_name, message_json)
135
135
  message = ActiveRecordStreams::Message.from_json(message_json)
136
136
  ActiveRecordStreams.config.streams.each do |stream|
137
- stream.publish(table_name, message)
137
+ # Use `handle_error: false` to raise exceptions instead of
138
+ # calling `error_handler`, this will let he Sidekiq to
139
+ # perform retries on it's own
140
+ stream.publish(table_name, message, handle_error: false)
138
141
  end
139
142
  end
140
143
  end
@@ -30,7 +30,12 @@ module ActiveRecordStreams
30
30
  @error_handler = error_handler
31
31
  end
32
32
 
33
- def publish(table_name, message)
33
+ ##
34
+ # @param [String] table_name
35
+ # @param [ActiveRecordStreams::Message] message
36
+ # @param [Boolean] handle_error
37
+
38
+ def publish(table_name, message, handle_error: true)
34
39
  return unless (any_table? && allowed_table?(table_name)) ||
35
40
  table_name == @table_name
36
41
 
@@ -38,7 +43,7 @@ module ActiveRecordStreams
38
43
  response = http.request(request)
39
44
  assert_response_code(response)
40
45
  rescue StandardError => e
41
- raise e unless @error_handler.is_a?(Proc)
46
+ raise e unless call_error_handler?(handle_error)
42
47
 
43
48
  @error_handler.call(self, table_name, message, e)
44
49
  end
@@ -82,6 +87,10 @@ module ActiveRecordStreams
82
87
 
83
88
  raise StandardError, response.body
84
89
  end
90
+
91
+ def call_error_handler?(handle_error)
92
+ @error_handler.is_a?(Proc) && handle_error
93
+ end
85
94
  end
86
95
  end
87
96
  end
@@ -89,6 +89,18 @@ RSpec.describe ActiveRecordStreams::Publishers::HttpStream do
89
89
  end
90
90
  end
91
91
 
92
+ context 'error response with error handling off' do
93
+ let(:response) { double(body: 'Error', code: 400) }
94
+ let(:error_handler) { Proc.new {} }
95
+
96
+ it 'raises exception' do
97
+ expect(error_handler).not_to receive(:call)
98
+
99
+ expect { subject.publish(actual_table_name, message, handle_error: false) }
100
+ .to raise_error(StandardError)
101
+ end
102
+ end
103
+
92
104
  context 'https target' do
93
105
  let(:url) { 'https://hello.world' }
94
106
 
@@ -32,15 +32,16 @@ module ActiveRecordStreams
32
32
  ##
33
33
  # @param [String] table_name
34
34
  # @param [ActiveRecordStreams::Message] message
35
+ # @param [Boolean] handle_error
35
36
 
36
- def publish(table_name, message)
37
+ def publish(table_name, message, handle_error: true)
37
38
  return unless (any_table? && allowed_table?(table_name)) ||
38
39
  table_name == @table_name
39
40
 
40
41
  client.publish(@stream_name, partition_key(table_name),
41
42
  message.json, @overrides)
42
43
  rescue StandardError => e
43
- raise e unless @error_handler.is_a?(Proc)
44
+ raise e unless call_error_handler?(handle_error)
44
45
 
45
46
  @error_handler.call(self, table_name, message, e)
46
47
  end
@@ -55,6 +56,10 @@ module ActiveRecordStreams
55
56
  !@ignored_tables.include?(table_name)
56
57
  end
57
58
 
59
+ def call_error_handler?(handle_error)
60
+ @error_handler.is_a?(Proc) && handle_error
61
+ end
62
+
58
63
  def partition_key(table_name)
59
64
  "#{table_name}-#{Time.now.utc.strftime(PARTITION_KEY_TIME_FORMAT)}"
60
65
  end
@@ -110,5 +110,20 @@ RSpec.describe ActiveRecordStreams::Publishers::KinesisStream do
110
110
  subject.publish(actual_table_name, message)
111
111
  end
112
112
  end
113
+
114
+ context 'delivery error error with error handling off' do
115
+ let(:error_handler) { Proc.new {} }
116
+
117
+ it 'raises exception' do
118
+ expect(kinesis_client).to receive(:publish) do
119
+ raise StandardError, 'Delivery error'
120
+ end
121
+
122
+ expect(error_handler).not_to receive(:call)
123
+
124
+ expect { subject.publish(actual_table_name, message, handle_error: false) }
125
+ .to raise_error(StandardError)
126
+ end
127
+ end
113
128
  end
114
129
  end
@@ -29,14 +29,15 @@ module ActiveRecordStreams
29
29
  ##
30
30
  # @param [String] table_name
31
31
  # @param [ActiveRecordStreams::Message] message
32
+ # @param [Boolean] handle_error
32
33
 
33
- def publish(table_name, message)
34
+ def publish(table_name, message, handle_error: true)
34
35
  return unless (any_table? && allowed_table?(table_name)) ||
35
36
  table_name == @table_name
36
37
 
37
38
  client.publish(@topic_arn, message.json, @overrides)
38
39
  rescue StandardError => e
39
- raise e unless @error_handler.is_a?(Proc)
40
+ raise e unless call_error_handler?(handle_error)
40
41
 
41
42
  @error_handler.call(self, table_name, message, e)
42
43
  end
@@ -51,6 +52,10 @@ module ActiveRecordStreams
51
52
  !@ignored_tables.include?(table_name)
52
53
  end
53
54
 
55
+ def call_error_handler?(handle_error)
56
+ @error_handler.is_a?(Proc) && handle_error
57
+ end
58
+
54
59
  def client
55
60
  @client ||= SnsClient.new
56
61
  end
@@ -106,5 +106,20 @@ RSpec.describe ActiveRecordStreams::Publishers::SnsStream do
106
106
  subject.publish(actual_table_name, message)
107
107
  end
108
108
  end
109
+
110
+ context 'delivery error with error handling off' do
111
+ let(:error_handler) { Proc.new {} }
112
+
113
+ it 'raises exception' do
114
+ expect(sns_client).to receive(:publish) do
115
+ raise StandardError, 'Delivery error'
116
+ end
117
+
118
+ expect(error_handler).not_to receive(:call)
119
+
120
+ expect { subject.publish(actual_table_name, message, handle_error: false) }
121
+ .to raise_error(StandardError)
122
+ end
123
+ end
109
124
  end
110
125
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordStreams
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
@@ -4,6 +4,6 @@ require_relative 'version'
4
4
 
5
5
  RSpec.describe ActiveRecordStreams::VERSION do
6
6
  it 'has a version number' do
7
- expect(subject).to eq('0.1.3')
7
+ expect(subject).to eq('0.1.4')
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_streams
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Advanon Team