brow 0.4.0 → 0.4.1

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
  SHA256:
3
- metadata.gz: 6b51fe73e4a857aa33f3546cf5d7f0e434f467c19e585e00e8b7a5535765d0b4
4
- data.tar.gz: b36b39d1293d6b32940b5f9306c7a679c6438cc76377ea376560223343c3e6e3
3
+ metadata.gz: 1e823ebd67a0230133814bbdd5adc0463f2a6e2fe730b54ee2b55ecb925d347f
4
+ data.tar.gz: 5168d92d78eae8958098cacee8b0c4a25b140a52a6a3b08f7bd1e8e9388056ba
5
5
  SHA512:
6
- metadata.gz: 7bea156ce56ed4bc49688db5dfd9ce810fcbc6e6a18513445dc734792374b0831063e7ac831c9a1eed4f50459d95cef38181afa3071e5336e1f671a576844938
7
- data.tar.gz: ad5cc322c41f678f7de7df6add329defc9c90789fbe2a71df62156d58500a3b65648dacf0bc5bdeb0d986a5d2f542cccceb6e85dd55ef9b679c23a18f81ffc90
6
+ metadata.gz: aeaa195ffd0be0945d088219d0dd60451d5ef445bee52f35c3f6d379dc2fbbc7ec5784fe0cf0cfd32a771235e87ae607b85173ef264cb4107311026c613befae
7
+ data.tar.gz: '09f9ae0b7030d6daab14014d31e705d2df68d099ea5fe66a217dcde23fba3b9fededab0f25663651f354174efd2b0e23aa01cbc8faa0e0c6394ab1805ef1567a'
data/CHANGELOG.md CHANGED
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.4.1] - 2021-11-05
9
+
10
+ - Move progname to logg message so it always appears (5ad1596df79f14d06d7b6dc508b1d5a9282aeebb and 531a999067d398daadc4b13d501e7044bcd3b709)
11
+ - Fix echo server in examples (53eea5af37a888666e8740eac196832b3f67dfc7).
12
+
8
13
  ## [0.4.0] - 2021-11-04
9
14
 
10
15
  ### Added
@@ -10,8 +10,8 @@ require "socket"
10
10
  require "thread"
11
11
  require "logger"
12
12
  require "json"
13
- require "rack"
14
- require "rack/handler/webrick"
13
+ require "singleton"
14
+ require "webrick"
15
15
 
16
16
  class EchoServer
17
17
  include Singleton
@@ -33,11 +33,11 @@ class EchoServer
33
33
  ],
34
34
  })
35
35
 
36
- @server.mount '/', Rack::Handler::WEBrick, ->(env) {
37
- request = Rack::Request.new(env)
38
- @logger.debug JSON.parse(request.body.read).inspect
39
- [200, {}, [""]]
40
- }
36
+ @server.mount_proc '/' do |request, response|
37
+ @logger.debug JSON.parse(request.body).inspect
38
+ response.header["Content-Type"] = "application/json"
39
+ response.body = "{}"
40
+ end
41
41
 
42
42
  @thread = Thread.new { @server.start }
43
43
  Timeout.timeout(10) { :wait until @started }
@@ -50,7 +50,7 @@ module Brow
50
50
  message_json_size = message_json.bytesize
51
51
 
52
52
  if message_too_big?(message_json_size)
53
- @logger.error("[brow]") { 'a message exceeded the maximum allowed size' }
53
+ @logger.error { "#{LOG_PREFIX} a message exceeded the maximum allowed size" }
54
54
  else
55
55
  @messages << message
56
56
  @json_size += message_json_size + 1 # One byte for the comma
@@ -86,16 +86,16 @@ module Brow
86
86
  #
87
87
  # @return [Response] API response
88
88
  def send_batch(batch)
89
- logger.debug("[brow]") { "Sending request for #{batch.length} items" }
89
+ logger.debug { "#{LOG_PREFIX} Sending request for #{batch.length} items" }
90
90
 
91
91
  last_response, exception = retry_with_backoff(retries) do
92
92
  response = send_request(batch)
93
- logger.debug("[brow]") { "Response: status=#{response.code}, body=#{response.body}" }
93
+ logger.debug { "#{LOG_PREFIX} Response: status=#{response.code}, body=#{response.body}" }
94
94
  [Response.new(response.code.to_i, nil), retry?(response)]
95
95
  end
96
96
 
97
97
  if exception
98
- logger.error("[brow]") { exception.message }
98
+ logger.error { "#{LOG_PREFIX} #{exception.message}" }
99
99
  exception.backtrace.each { |line| logger.error(line) }
100
100
  Response.new(-1, exception.to_s)
101
101
  else
@@ -108,7 +108,7 @@ module Brow
108
108
 
109
109
  # Closes a persistent connection if it exists
110
110
  def shutdown
111
- logger.info("[brow]") { "Transport shutting down" }
111
+ logger.info { "#{LOG_PREFIX} Transport shutting down" }
112
112
  @http.finish if @http.started?
113
113
  end
114
114
 
@@ -118,15 +118,15 @@ module Brow
118
118
  status_code = response.code.to_i
119
119
  if status_code >= 500
120
120
  # Server error. Retry and log.
121
- logger.info("[brow]") { "Server error: status=#{status_code}, body=#{response.body}" }
121
+ logger.info { "#{LOG_PREFIX} Server error: status=#{status_code}, body=#{response.body}" }
122
122
  true
123
123
  elsif status_code == 429
124
124
  # Rate limited. Retry and log.
125
- logger.info("[brow]") { "Rate limit error: body=#{response.body}" }
125
+ logger.info { "#{LOG_PREFIX} Rate limit error: body=#{response.body}" }
126
126
  true
127
127
  elsif status_code >= 400
128
128
  # Client error. Do not retry, but log.
129
- logger.error("[brow]") { "Client error: status=#{status_code}, body=#{response.body}" }
129
+ logger.error { "#{LOG_PREFIX} Client error: status=#{status_code}, body=#{response.body}" }
130
130
  false
131
131
  else
132
132
  false
@@ -148,13 +148,13 @@ module Brow
148
148
  result, should_retry = yield
149
149
  return [result, nil] unless should_retry
150
150
  rescue StandardError => error
151
- logger.debug("[brow]") { "Request error: #{error}" }
151
+ logger.debug { "#{LOG_PREFIX} Request error: #{error}" }
152
152
  should_retry = true
153
153
  caught_exception = error
154
154
  end
155
155
 
156
156
  if should_retry && (retries_remaining > 1)
157
- logger.debug("[brow]") { "Retrying request, #{retries_remaining} retries left" }
157
+ logger.debug { "#{LOG_PREFIX} Retrying request, #{retries_remaining} retries left" }
158
158
  sleep(@backoff_policy.next_interval.to_f / 1000)
159
159
  retry_with_backoff(retries_remaining - 1, &block)
160
160
  else
data/lib/brow/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Brow
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
data/lib/brow/worker.rb CHANGED
@@ -96,7 +96,7 @@ module Brow
96
96
  queue << data
97
97
  true
98
98
  else
99
- logger.warn("[brow]") { "Queue is full, dropping events. The :max_queue_size configuration parameter can be increased to prevent this from happening." }
99
+ logger.warn { "#{LOG_PREFIX} Queue is full, dropping events. The :max_queue_size configuration parameter can be increased to prevent this from happening." }
100
100
  false
101
101
  end
102
102
  end
@@ -112,12 +112,12 @@ module Brow
112
112
  if @thread
113
113
  begin
114
114
  if @thread.join(shutdown_timeout)
115
- logger.info("[brow]") { "Worker thread [#{@thread.object_id}] joined sucessfully" }
115
+ logger.info { "#{LOG_PREFIX} Worker thread [#{@thread.object_id}] joined sucessfully" }
116
116
  else
117
- logger.info("[brow]") { "Worker thread [#{@thread.object_id}] did not join successfully" }
117
+ logger.info { "#{LOG_PREFIX} Worker thread [#{@thread.object_id}] did not join successfully" }
118
118
  end
119
119
  rescue => error
120
- logger.info("[brow]") { "Worker thread [#{@thread.object_id}] error shutting down: #{error.inspect}" }
120
+ logger.info { "#{LOG_PREFIX} Worker thread [#{@thread.object_id}] error shutting down: #{error.inspect}" }
121
121
  end
122
122
  end
123
123
  end
@@ -131,7 +131,7 @@ module Brow
131
131
 
132
132
  case message
133
133
  when SHUTDOWN
134
- logger.info("[brow]") { "Worker shutting down" }
134
+ logger.info { "#{LOG_PREFIX} Worker shutting down" }
135
135
  send_batch(batch) unless batch.empty?
136
136
  break
137
137
  else
@@ -165,7 +165,7 @@ module Brow
165
165
  begin
166
166
  return if thread_alive?
167
167
  @thread = Thread.new { run }
168
- logger.debug("[brow]") { "Worker thread [#{@thread.object_id}] started" }
168
+ logger.debug { "#{LOG_PREFIX} Worker thread [#{@thread.object_id}] started" }
169
169
  ensure
170
170
  mutex.unlock
171
171
  end
data/lib/brow.rb CHANGED
@@ -6,6 +6,9 @@ require "logger"
6
6
  module Brow
7
7
  class Error < StandardError; end
8
8
 
9
+ # Private
10
+ LOG_PREFIX = "[brow]"
11
+
9
12
  # Public: Returns the logger instance to use for logging of things.
10
13
  def self.logger
11
14
  return @logger if @logger
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-04 00:00:00.000000000 Z
11
+ date: 2021-11-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: