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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb4a01b20ccfb91b90a44a87a51acfc9c60a484450a86b47e73a955761a41365
4
- data.tar.gz: 73dfe494f6dd8b867f45b8346f0d2dce8ba91e56e40e83dbf967fb4a8f2c1841
3
+ metadata.gz: 1def66ffdef1ce2d2c100dea3b74a3d69fc5c17ef0c57071ef25cd7cbe4016ad
4
+ data.tar.gz: 8198710b789bfa1d49291b020e652e2ab5a7a80e17ccb4ef6a653b3416702342
5
5
  SHA512:
6
- metadata.gz: 5b2d334a5e2564c79ba4e1f91ba6ffd1e44001f52ec738d47e4c98096b0d76f6f203d14712b393739b1edbfc2af0e66f7809ed7018e63a777765e2e0f577eca5
7
- data.tar.gz: c3ccceb024017953c57645678c1fa32a943d8a7dfdf2808d5066e22731ba75547483ddca686e2d00e9a1d5e6816cdd6b3d434d3723ce7722a8a3b7cf57410b5f
6
+ metadata.gz: f4329d9e10df97ce40c90badf31b65db2379a568b96f90e311e407ce866bbb953e5fccb0a55bf16c006424fe7ecf1e6a6901e513060795f9fabfa7e5b7d36a55
7
+ data.tar.gz: b04998e5e3786d1c7ab6d9ba9364643709e47f9ba9f753df59edfa3e967e312755b429c47198e10950ee899e972d8330d9aa414849199501de1d41657da45e97
@@ -3,7 +3,7 @@ name: Execute Specs
3
3
  on: [push]
4
4
 
5
5
  jobs:
6
- build:
6
+ rspec:
7
7
 
8
8
  runs-on: ubuntu-latest
9
9
 
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(payload: JSON.dump(pageview), topic: "pageviews-with-country", key: pageview["id"])
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
 
@@ -18,6 +18,10 @@ module Racecar
18
18
  @config ||= Config.new
19
19
  end
20
20
 
21
+ def self.config=(config)
22
+ @config = config
23
+ end
24
+
21
25
  def self.configure
22
26
  yield config
23
27
  end
@@ -23,7 +23,7 @@ module Racecar
23
23
  def run
24
24
  $stderr.puts "=> Starting Racecar consumer #{consumer_name}..."
25
25
 
26
- RailsConfigFileLoader.load!
26
+ RailsConfigFileLoader.load! unless config.without_rails?
27
27
 
28
28
  if File.exist?("config/racecar.rb")
29
29
  require "./config/racecar"
@@ -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
 
@@ -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
- retried ||= false
16
- msg = current.poll(timeout_ms)
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
- raise if retried
19
- retried = true
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
- msg = poll(timeout_ms)
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
@@ -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, :value, :headers
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
@@ -1,3 +1,3 @@
1
1
  module Racecar
2
- VERSION = "2.0.0.alpha3"
2
+ VERSION = "2.0.0.beta1"
3
3
  end
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.alpha3
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: 2019-09-18 00:00:00.000000000 Z
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/ci.yml"
114
+ - ".github/workflows/rspec.yml"
115
115
  - ".gitignore"
116
116
  - ".rspec"
117
117
  - CHANGELOG.md