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 +4 -4
- data/CHANGELOG.md +5 -0
- data/examples/echo_server.rb +7 -7
- data/lib/brow/message_batch.rb +1 -1
- data/lib/brow/transport.rb +9 -9
- data/lib/brow/version.rb +1 -1
- data/lib/brow/worker.rb +6 -6
- data/lib/brow.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e823ebd67a0230133814bbdd5adc0463f2a6e2fe730b54ee2b55ecb925d347f
|
4
|
+
data.tar.gz: 5168d92d78eae8958098cacee8b0c4a25b140a52a6a3b08f7bd1e8e9388056ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/examples/echo_server.rb
CHANGED
@@ -10,8 +10,8 @@ require "socket"
|
|
10
10
|
require "thread"
|
11
11
|
require "logger"
|
12
12
|
require "json"
|
13
|
-
require "
|
14
|
-
require "
|
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.
|
37
|
-
|
38
|
-
|
39
|
-
|
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 }
|
data/lib/brow/message_batch.rb
CHANGED
@@ -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
|
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
|
data/lib/brow/transport.rb
CHANGED
@@ -86,16 +86,16 @@ module Brow
|
|
86
86
|
#
|
87
87
|
# @return [Response] API response
|
88
88
|
def send_batch(batch)
|
89
|
-
logger.debug
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
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
|
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
|
115
|
+
logger.info { "#{LOG_PREFIX} Worker thread [#{@thread.object_id}] joined sucessfully" }
|
116
116
|
else
|
117
|
-
logger.info
|
117
|
+
logger.info { "#{LOG_PREFIX} Worker thread [#{@thread.object_id}] did not join successfully" }
|
118
118
|
end
|
119
119
|
rescue => error
|
120
|
-
logger.info
|
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
|
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
|
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
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.
|
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-
|
11
|
+
date: 2021-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|