deimos-ruby 1.0.0.pre.beta22 → 1.0.0.pre.beta23

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: 907d55a8c7e56e87ff98674d7b07f2946e6d1543aeeffaf36da7fe15e5556cc2
4
- data.tar.gz: f92ce4eb4ebb455db022e66924885e2c0144c2485f10a152d187781b13d69645
3
+ metadata.gz: a7de207dcf4a09b8881881cfbb6af9c007c48083e091344ed3401e4a6fb944fb
4
+ data.tar.gz: 662ecac0adcd71cd8bf4bb44fa70436a88844d4ef65c76f8a2f341c964ae2cd8
5
5
  SHA512:
6
- metadata.gz: a947fe880133b5f93a076a618b882309b689160d3baa8aa91f0b12deadec1ffe326138900d97cbda82db92843b200af86b7ac40b20e3aaa7afce2bf24a25a80c
7
- data.tar.gz: d9fac9b0fe096bd6a69bcebb6c2daa0ae121feb593ded2192a5c7c5316b7631555c9d88634095ef019ee6e71300ad80e2733d5114c90f450d048664b970bd2aa
6
+ metadata.gz: 4508f6fb52f68a89b57cdda8bf46d1069d2359c3fafd9e12e099601ed5b474a36739958a56fa4c796584eec73ae1eac3e8e31aab121d139a9a8ee6dac7797fc2
7
+ data.tar.gz: b2b31653474653660fd0e4fac2af4843954c39b1525604fb7ff9fa39aa14f6e982627ad1da48c655077f4ad3143253ee923043229b36f6cf44d03135fb4c873a
data/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ 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
+ ## [1.0.0-beta23] - 2019-08-22
9
+ - Fix bug where nil payloads were not being saved to the DB.
10
+ - Fix DB producer rake task looking at THREADS env var instead of THREAD_COUNT.
11
+ - Debug messages in the DB producer if debug logs are turned on.
12
+ - Changed logger in specs to info.
13
+
8
14
  ## [1.0.0-beta22] - 2019-08-09
9
15
  - Add `pending_db_messages_max_wait` metric for the DB producer.
10
16
  - Fix mock metrics to allow optional option hashes.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deimos-ruby (1.0.0.pre.beta22)
4
+ deimos-ruby (1.0.0.pre.beta23)
5
5
  avro-patches (~> 0.3)
6
6
  avro_turf (~> 0.8)
7
7
  phobos (~> 1.8)
File without changes
@@ -5,7 +5,7 @@ module Deimos
5
5
  class KafkaMessage < ActiveRecord::Base
6
6
  self.table_name = 'kafka_messages'
7
7
 
8
- validates_presence_of :message, :topic
8
+ validates_presence_of :topic
9
9
 
10
10
  # Ensure it gets turned into a string, e.g. for testing purposes. It
11
11
  # should already be a string.
@@ -23,5 +23,6 @@ module Deimos
23
23
  topic: self.topic
24
24
  }
25
25
  end
26
+
26
27
  end
27
28
  end
@@ -93,14 +93,13 @@ module Deimos
93
93
 
94
94
  # This will contain an array of hashes, where each hash is the actual
95
95
  # attribute hash that created the object.
96
- ids =
97
- ids = if results.is_a?(Array)
98
- results[1]
99
- elsif results.respond_to?(:ids)
100
- results.ids
101
- else
102
- []
103
- end
96
+ ids = if results.is_a?(Array)
97
+ results[1]
98
+ elsif results.respond_to?(:ids)
99
+ results.ids
100
+ else
101
+ []
102
+ end
104
103
  if ids.blank?
105
104
  # re-fill IDs based on what was just entered into the DB.
106
105
  if self.connection.adapter_name.downcase =~ /sqlite/
@@ -66,7 +66,7 @@ module Deimos
66
66
  locked_at: Time.zone.now,
67
67
  error: true,
68
68
  retries: record.retries + 1 }
69
- if Rails::VERSION::MAJOR >= 4
69
+ if ActiveRecord::VERSION::MAJOR >= 4
70
70
  record.update!(attr_hash)
71
71
  else
72
72
  record.update_attributes!(attr_hash)
@@ -62,6 +62,22 @@ module Deimos
62
62
  messages = retrieve_messages
63
63
 
64
64
  while messages.any?
65
+ @logger.debug do
66
+ producer = Deimos::Producer.descendants.find { |c| c.topic == topic }
67
+ decoded_messages = if producer
68
+ consumer = Class.new(Deimos::Consumer)
69
+ consumer.config.merge!(producer.config)
70
+ messages.map do |message|
71
+ {
72
+ :key => message[:key].present? ? consumer.new.decode_key(message[:key]) : nil,
73
+ :message => consumer.decoder.decode(message[:payload])
74
+ }
75
+ end
76
+ else
77
+ messages
78
+ end
79
+ "DB producer: Topic #{topic} Producing messages: #{decoded_messages}"
80
+ end
65
81
  produce_messages(messages.map(&:phobos_message))
66
82
  messages.first.class.where(id: messages.map(&:id)).delete_all
67
83
  break if messages.size < BATCH_SIZE
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deimos
4
- VERSION = '1.0.0-beta22'
4
+ VERSION = '1.0.0-beta23'
5
5
  end
@@ -20,7 +20,7 @@ namespace :deimos do
20
20
  ENV['DEIMOS_RAKE_TASK'] = 'true'
21
21
  STDOUT.sync = true
22
22
  Rails.logger.info('Running deimos:db_producer rake task.')
23
- thread_count = ENV['THREADS'].presence || 1
23
+ thread_count = ENV['THREAD_COUNT'].to_i.zero? ? 1 : ENV['THREAD_COUNT'].to_i
24
24
  Deimos.start_db_backend!(thread_count: thread_count)
25
25
  end
26
26
 
@@ -23,6 +23,13 @@ each_db_config(Deimos::Backends::Db) do
23
23
  'key' => 'foo3'
24
24
  )
25
25
  end
26
+
27
+ it 'should add nil messages' do
28
+ described_class.publish(producer_class: MyProducer,
29
+ messages: [build_message(nil, 'my-topic', "foo1")])
30
+ expect(Deimos::KafkaMessage.count).to eq(1)
31
+ end
32
+
26
33
  it 'should add to non-keyed messages' do
27
34
  described_class.publish(producer_class: MyNoKeyProducer,
28
35
  messages: messages)
data/spec/spec_helper.rb CHANGED
@@ -7,6 +7,7 @@ require 'deimos/metrics/mock'
7
7
  require 'deimos/tracing/mock'
8
8
  require 'deimos/test_helpers'
9
9
  require 'active_support/testing/time_helpers'
10
+ require 'activerecord-import'
10
11
 
11
12
  # Helpers for Executor/DbProducer
12
13
  module TestRunners
@@ -141,17 +142,18 @@ RSpec.configure do |config|
141
142
  Time.zone = 'EST'
142
143
  ActiveRecord::Base.logger = Logger.new('/dev/null')
143
144
  setup_db(DbConfigs::DB_OPTIONS.last)
144
- Deimos.configure do |fr_config|
145
- fr_config.phobos_config_file = File.join(File.dirname(__FILE__), 'phobos.yml')
146
- fr_config.schema_path = File.join(File.expand_path(__dir__), 'schemas')
147
- fr_config.reraise_consumer_errors = true
148
- fr_config.schema_registry_url = ENV['SCHEMA_REGISTRY'] || 'http://localhost:8081'
149
- fr_config.seed_broker = ENV['KAFKA_SEED_BROKER'] || 'localhost:9092'
150
- fr_config.logger = Logger.new('/dev/null')
145
+ Deimos.configure do |deimos_config|
146
+ deimos_config.phobos_config_file = File.join(File.dirname(__FILE__), 'phobos.yml')
147
+ deimos_config.schema_path = File.join(File.expand_path(__dir__), 'schemas')
148
+ deimos_config.reraise_consumer_errors = true
149
+ deimos_config.schema_registry_url = ENV['SCHEMA_REGISTRY'] || 'http://localhost:8081'
150
+ deimos_config.seed_broker = ENV['KAFKA_SEED_BROKER'] || 'localhost:9092'
151
+ deimos_config.logger = Logger.new('/dev/null')
152
+ deimos_config.logger.level = Logger::INFO
151
153
 
152
154
  # Use Mock Metrics and Tracing for rspecs
153
- fr_config.metrics = Deimos::Metrics::Mock.new
154
- fr_config.tracer = Deimos::Tracing::Mock.new
155
+ deimos_config.metrics = Deimos::Metrics::Mock.new
156
+ deimos_config.tracer = Deimos::Tracing::Mock.new
155
157
  end
156
158
  end
157
159
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deimos-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.beta22
4
+ version: 1.0.0.pre.beta23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-09 00:00:00.000000000 Z
11
+ date: 2019-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro-patches
@@ -315,7 +315,7 @@ files:
315
315
  - README.md
316
316
  - Rakefile
317
317
  - bin/deimos
318
- - deimos-kafka.gemspec
318
+ - deimos-ruby.gemspec
319
319
  - docker-compose.yml
320
320
  - docs/DATABASE_BACKEND.md
321
321
  - docs/PULL_REQUEST_TEMPLATE.md