protor 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad691eb787f99113726a4f61651f09aa348f6de5
4
- data.tar.gz: d2f648b3755ef1f0a639da1d7fa4011182999177
3
+ metadata.gz: ff72000d5fb00510aa40d7f08df563673744c9d7
4
+ data.tar.gz: e59aa78f2b2c9b089cba768a4af71d5aafe22109
5
5
  SHA512:
6
- metadata.gz: 6d921445028e782c9ab2e740a8ea948aa8ff450f9f73fe32ce802814627ba65c62da1f6fd641da211b22a17550e5a10952e0b38b75d08961811b14aa72543d56
7
- data.tar.gz: 8ddfb02f2efc54fdb8e9004aca249243778110771c446cf567ef52e20524a156152b8b6ded357d778d71e0636277222b60c65692b4648396f35fc682ed481220
6
+ metadata.gz: ce72db467c7c6b848a5d247a9f83bed21ec53bcb33262f6e54a9daab6a9c5ae38e9f0a739b89fdc57a829bae304948dac21ece0df1bc2c6b187a9a9b96eda133
7
+ data.tar.gz: c78d3d8ec843cf4a8865498bb56a8167e86df98b9838e71276431abc78ccadfbcd4059161205f891780ea1a8fe13bc55423688059e5d55cd70304f311c9c42e3
@@ -4,27 +4,47 @@ module Protor
4
4
  class Client
5
5
  def initialize(configuration)
6
6
  @options = configuration
7
+ @retries = 0
7
8
  end
8
9
 
9
10
  def publish(payload)
10
- established do |connection|
11
- payload.each{ |str| connection.send(str, 0) }
11
+ connect
12
+ payload.each do |message|
13
+ send(message)
12
14
  end
15
+ rescue Errno::EPERM, Errno::ECONNREFUSED => e
16
+ options.logger.error(e)
17
+ ensure
18
+ close
13
19
  end
14
20
 
15
21
  private
16
22
 
17
- attr_reader :options
23
+ attr_reader :options, :connection, :retries
18
24
 
19
- def established
20
- socket = UDPSocket.new
21
- socket.connect(options.host, options.port)
22
- yield socket
23
- rescue Errno::ECONNREFUSED => exception
24
- # omit error, it caused by aggregate server being down
25
- exception
26
- ensure
27
- socket.close unless socket.closed?
25
+ def send(message)
26
+ connection.send(message, 0)
27
+ rescue Errno::EPERM => exception
28
+ retries += 1
29
+ if retries <= 3
30
+ refresh && retry
31
+ else
32
+ raise exception
33
+ end
34
+ end
35
+
36
+ def connect
37
+ @connection = UDPSocket.new
38
+ @connection.connect(options.host, options.port)
39
+ end
40
+
41
+ def refresh
42
+ close
43
+ connect
44
+ end
45
+
46
+ def close
47
+ connection.close unless connection.closed?
28
48
  end
29
49
  end
30
50
  end
@@ -1,6 +1,8 @@
1
+ require 'logger'
2
+
1
3
  module Protor
2
4
  class Configuration
3
- attr_writer :host, :port, :max_packet_size
5
+ attr_writer :host, :port, :max_packet_size, :logger
4
6
 
5
7
  def host
6
8
  @host ||= 'localhost'
@@ -13,5 +15,9 @@ module Protor
13
15
  def max_packet_size
14
16
  @max_packet_size ||= 56_607
15
17
  end
18
+
19
+ def logger
20
+ @logger ||= Logger.new(STDOUT)
21
+ end
16
22
  end
17
23
  end
@@ -1,3 +1,3 @@
1
1
  module Protor
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roland Rinfandi Utama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-26 00:00:00.000000000 Z
11
+ date: 2016-10-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -51,3 +51,4 @@ signing_key:
51
51
  specification_version: 4
52
52
  summary: Prometheus aggregator client for ruby.
53
53
  test_files: []
54
+ has_rdoc: