racecar 2.0.0.alpha3 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/{ci.yml → rspec.yml} +1 -1
- data/README.md +4 -1
- data/lib/racecar.rb +4 -0
- data/lib/racecar/cli.rb +1 -1
- data/lib/racecar/config.rb +3 -0
- data/lib/racecar/consumer_set.rb +25 -9
- data/lib/racecar/message.rb +5 -1
- data/lib/racecar/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1def66ffdef1ce2d2c100dea3b74a3d69fc5c17ef0c57071ef25cd7cbe4016ad
|
4
|
+
data.tar.gz: 8198710b789bfa1d49291b020e652e2ab5a7a80e17ccb4ef6a653b3416702342
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4329d9e10df97ce40c90badf31b65db2379a568b96f90e311e407ce866bbb953e5fccb0a55bf16c006424fe7ecf1e6a6901e513060795f9fabfa7e5b7d36a55
|
7
|
+
data.tar.gz: b04998e5e3786d1c7ab6d9ba9364643709e47f9ba9f753df59edfa3e967e312755b429c47198e10950ee899e972d8330d9aa414849199501de1d41657da45e97
|
data/README.md
CHANGED
@@ -214,7 +214,7 @@ class GeoCodingConsumer < Racecar::Consumer
|
|
214
214
|
|
215
215
|
# The `produce` method enqueues a message to be delivered after #process
|
216
216
|
# returns. It won't actually deliver the message.
|
217
|
-
produce(
|
217
|
+
produce(JSON.dump(pageview), topic: "pageviews-with-country", key: pageview["id"])
|
218
218
|
end
|
219
219
|
end
|
220
220
|
```
|
@@ -319,6 +319,9 @@ Racecar supports configuring ruby-kafka's [Datadog](https://www.datadoghq.com/)
|
|
319
319
|
* `datadog_namespace` – The namespace to use for Datadog metrics.
|
320
320
|
* `datadog_tags` – Tags that should always be set on Datadog metrics.
|
321
321
|
|
322
|
+
#### Consumers Without Rails ####
|
323
|
+
|
324
|
+
By default, if Rails is detected, it will be automatically started when the consumer is started. There are cases where you might not want or need Rails. You can pass the `--without-rails` option when starting the consumer and Rails won't be started.
|
322
325
|
|
323
326
|
### Testing consumers
|
324
327
|
|
data/lib/racecar.rb
CHANGED
data/lib/racecar/cli.rb
CHANGED
data/lib/racecar/config.rb
CHANGED
@@ -136,6 +136,9 @@ module Racecar
|
|
136
136
|
desc "Whether to check the server certificate is valid for the hostname"
|
137
137
|
boolean :ssl_verify_hostname, default: true
|
138
138
|
|
139
|
+
desc "Whether to boot Rails when starting the consumer"
|
140
|
+
boolean :without_rails, default: false
|
141
|
+
|
139
142
|
# The error handler must be set directly on the object.
|
140
143
|
attr_reader :error_handler
|
141
144
|
|
data/lib/racecar/consumer_set.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Racecar
|
2
2
|
class ConsumerSet
|
3
|
+
MAX_POLL_TRIES = 10
|
4
|
+
|
3
5
|
def initialize(config, logger)
|
4
6
|
@config, @logger = config, logger
|
5
7
|
raise ArgumentError, "Subscriptions must not be empty when subscribing" if @config.subscriptions.empty?
|
@@ -12,21 +14,28 @@ module Racecar
|
|
12
14
|
|
13
15
|
def poll(timeout_ms)
|
14
16
|
maybe_select_next_consumer
|
15
|
-
|
16
|
-
|
17
|
+
started_at ||= Time.now
|
18
|
+
try ||= 0
|
19
|
+
remain ||= timeout_ms
|
20
|
+
|
21
|
+
msg = remain <= 0 ? nil : current.poll(remain)
|
17
22
|
rescue Rdkafka::RdkafkaError => e
|
18
|
-
|
19
|
-
|
23
|
+
wait_before_retry_ms = 100 * (2**try) # 100ms, 200ms, 400ms, …
|
24
|
+
try += 1
|
25
|
+
raise if try >= MAX_POLL_TRIES || remain <= wait_before_retry_ms
|
20
26
|
|
21
|
-
@logger.error "Error for topic subscription #{current_subscription}: #{e}"
|
27
|
+
@logger.error "(try #{try}): Error for topic subscription #{current_subscription}: #{e}"
|
22
28
|
|
23
29
|
case e.code
|
24
30
|
when :max_poll_exceeded, :transport # -147, -195
|
25
31
|
reset_current_consumer
|
26
|
-
retry
|
27
|
-
else
|
28
|
-
raise
|
29
32
|
end
|
33
|
+
|
34
|
+
remain = remaining_time_ms(timeout_ms, started_at)
|
35
|
+
raise if remain <= wait_before_retry_ms
|
36
|
+
|
37
|
+
sleep wait_before_retry_ms/1000.0
|
38
|
+
retry
|
30
39
|
ensure
|
31
40
|
@last_poll_read_nil_message = true if msg.nil?
|
32
41
|
end
|
@@ -36,7 +45,9 @@ module Racecar
|
|
36
45
|
@batch_started_at = Time.now
|
37
46
|
@messages = []
|
38
47
|
while collect_messages_for_batch? do
|
39
|
-
|
48
|
+
remain = remaining_time_ms(timeout_ms, @batch_started_at)
|
49
|
+
break if remain <= 0
|
50
|
+
msg = poll(remain)
|
40
51
|
break if msg.nil?
|
41
52
|
@messages << msg
|
42
53
|
end
|
@@ -174,5 +185,10 @@ module Racecar
|
|
174
185
|
config.merge! subscription.additional_config
|
175
186
|
config
|
176
187
|
end
|
188
|
+
|
189
|
+
def remaining_time_ms(limit_ms, started_at_time)
|
190
|
+
r = limit_ms - ((Time.now - started_at_time)*1000).round
|
191
|
+
r <= 0 ? 0 : r
|
192
|
+
end
|
177
193
|
end
|
178
194
|
end
|
data/lib/racecar/message.rb
CHANGED
@@ -8,7 +8,11 @@ module Racecar
|
|
8
8
|
@rdkafka_message = rdkafka_message
|
9
9
|
end
|
10
10
|
|
11
|
-
def_delegators :@rdkafka_message, :topic, :partition, :offset, :key, :
|
11
|
+
def_delegators :@rdkafka_message, :topic, :partition, :offset, :key, :headers
|
12
|
+
|
13
|
+
def value
|
14
|
+
@rdkafka_message.payload
|
15
|
+
end
|
12
16
|
|
13
17
|
def create_time
|
14
18
|
@rdkafka_message.timestamp
|
data/lib/racecar/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: racecar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schierbeck
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-01-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: king_konf
|
@@ -111,7 +111,7 @@ executables:
|
|
111
111
|
extensions: []
|
112
112
|
extra_rdoc_files: []
|
113
113
|
files:
|
114
|
-
- ".github/workflows/
|
114
|
+
- ".github/workflows/rspec.yml"
|
115
115
|
- ".gitignore"
|
116
116
|
- ".rspec"
|
117
117
|
- CHANGELOG.md
|