rafka 0.0.6 → 0.0.7

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: 6ae73debb337586cf11886beb47e5d66d67d27d2
4
- data.tar.gz: 3d62f4c45b95bd07fab9b9962df6f50e1fea029a
3
+ metadata.gz: 4b373f61cafd171166bb214fca2e36d3f7e36c40
4
+ data.tar.gz: 3baee498081c2aabfd195074cdb2695ad5b4711a
5
5
  SHA512:
6
- metadata.gz: e21831f41604c1365b4d2af812edc060fbe5dd7e836b70b9c31b301bced22cc719dfd5c0fc9dfb06a74f1fae27b2788e2aba2b4df74de248ae869175606ed18d
7
- data.tar.gz: 4985998170015c38fdd9b89c7d619068cfded34cf4e1dca77b65756459c1be4b931bc5fea6da3bec60172d2b46aae83a3aa00e138989f3a0c92653cda31277fc
6
+ metadata.gz: caa3b522f9fc732d72be3aeba84c891223545651c41a8b61a4144ddbb0f5fcbac0673b8c17460358cb058cee21130df1f8819a70e3fb99c6e04461cb1ee2bcd7
7
+ data.tar.gz: 38c9e593ded9496547dbdf4b3445dbd7b622b3a232ae7c833fb7d0689dc9625b15b857f45e9c2d1ca246ed5a3086ee0cbfa46463794a9f61889cba9fd24de4d2
data/README.md CHANGED
@@ -3,7 +3,7 @@ rafka-rb: Ruby driver for Rafka
3
3
  [![Gem Version](https://badge.fury.io/rb/rafka.svg)](https://badge.fury.io/rb/rafka-rb)
4
4
  [![Documentation](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/skroutz/rafka-rb)
5
5
 
6
- Rafka is a thin Ruby client library for [Rafka](https://github.com/skroutz/rafka-rb),
6
+ Rafka is a thin Ruby client library for [Rafka](https://github.com/skroutz/rafka),
7
7
  providing a consumer and a producer with simple semantics. It is backed by
8
8
  [redis-rb](https://github.com/redis/redis-rb).
9
9
 
data/lib/rafka.rb CHANGED
@@ -12,7 +12,7 @@ module Rafka
12
12
  DEFAULTS = {
13
13
  host: "localhost",
14
14
  port: 6380,
15
- reconnect_attempts: 0,
15
+ reconnect_attempts: 5,
16
16
  }
17
17
 
18
18
  def self.wrap_errors
@@ -27,5 +27,29 @@ module Rafka
27
27
  raise CommandError, e.message
28
28
  end
29
29
  end
30
+
31
+ # redis-rb until 3.2.1 didn't retry to connect on
32
+ # Redis::CannotConnectError (eg. when rafka is down) so we manually retry
33
+ # 5 times
34
+ #
35
+ # TODO(agis): get rid of this method when we go to 3.2.1 or later, because
36
+ # https://github.com/redis/redis-rb/pull/476/
37
+ def self.with_retry(times: DEFAULTS[:reconnect_attempts], every_sec: 1)
38
+ attempts = 0
39
+
40
+ begin
41
+ yield
42
+ rescue Redis::CannotConnectError => e
43
+ if Gem::Version.new(Redis::VERSION) < Gem::Version.new("3.2.2")
44
+ if attempts < times
45
+ attempts += 1
46
+ sleep every_sec
47
+ retry
48
+ end
49
+ end
50
+
51
+ raise e
52
+ end
53
+ end
30
54
  end
31
55
 
@@ -35,19 +35,41 @@ module Rafka
35
35
  # @example
36
36
  # consume(5) { |msg| puts "I received #{msg.value}" }
37
37
  def consume(timeout=5)
38
- # in 3.2.2 and later this is done automatically
38
+ # redis-rb didn't automatically call `CLIENT SETNAME` until v3.2.2
39
+ # (https://github.com/redis/redis-rb/issues/510)
39
40
  #
40
- # @see https://github.com/redis/redis-rb/issues/510
41
- if !@connected && Gem::Version.new(Redis::VERSION) < Gem::Version.new("3.2.2")
42
- @redis.client.call([:client, :setname, @redis.id])
43
- @connected = true
41
+ # TODO(agis): get rid of this when we drop support for 3.2.1 and before
42
+ if !@redis.client.connected? && Gem::Version.new(Redis::VERSION) < Gem::Version.new("3.2.2")
43
+ Rafka.wrap_errors do
44
+ @redis.client.call([:client, :setname, @redis.id])
45
+ end
44
46
  end
45
47
 
46
48
  raised = false
47
49
  msg = nil
50
+ setname_attempts = 0
51
+
52
+ begin
53
+ Rafka.wrap_errors do
54
+ Rafka.with_retry do
55
+ msg = @redis.blpop(@topic, timeout: timeout)
56
+ end
57
+ end
58
+ rescue ConsumeError => e
59
+ # redis-rb didn't automatically call `CLIENT SETNAME` until v3.2.2
60
+ # (https://github.com/redis/redis-rb/issues/510)
61
+ #
62
+ # this is in case the server restarts while we were performing a BLPOP
63
+ #
64
+ # TODO(agis): get rid of this when we drop support for 3.2.1 and before
65
+ if e.message =~ /Identify yourself/ && setname_attempts < 5
66
+ sleep 0.5
67
+ @redis.client.call([:client, :setname, @redis.id])
68
+ setname_attempts += 1
69
+ retry
70
+ end
48
71
 
49
- Rafka.wrap_errors do
50
- msg = @redis.blpop(@topic, timeout: timeout)
72
+ raise e
51
73
  end
52
74
 
53
75
  return if !msg
data/lib/rafka/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rafka
2
- VERSION = "0.0.6".freeze
2
+ VERSION = "0.0.7".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Agis Anastasopoulos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-12 00:00:00.000000000 Z
11
+ date: 2017-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis