deimos-kafka 1.0.0.pre.beta16 → 1.0.0.pre.beta17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e0cb253905c806b2609cbce7566dc2fa987b9f2f49e91adcc38525cfe1a6a56
4
- data.tar.gz: cf80441d26aaf4e0a69aa96dc344ccd895474e7c2a4d1c2ae5f1ff2ac6d25a95
3
+ metadata.gz: 30b4706911af70b7e4662afdecf5b547583b74dbdebce492a7e57a9b1c9d504e
4
+ data.tar.gz: d5583aefa2e976497d8190398f0b04b2d07e33f6ff8f5ac79089bffa850b53f9
5
5
  SHA512:
6
- metadata.gz: 9483035eddaa55c3add6291f60c89c701c8c0b4fa220e6757890cae9c4e45282d20d1737247f2dbb15ee907d678529f6c0e0e0a00037bd504ae7cf8529a18e65
7
- data.tar.gz: da780f7e8a19e5a1e700d14cc3c80f2a659d905b0f9d1f064ccafef40dc4aec5e10b3b0eb50fd66843aea7bde3077f0fe3226425785fe21661110d67feb4be29
6
+ metadata.gz: 329ad07cc57cc869c1f9a843d74f70a428c7706882ce5bcabe8006afbc0e557f5931649ea4871973d21b5edd8d5e892dcf82ae5e0231a21e8b6e8021c2da187c
7
+ data.tar.gz: dc46360e6061b586b127888ac784b946fde6e9e5efe73173b8963aa1345fd65b58fe174e4fc69db37d9093ef17549c436087e1d35a73df555135c1d430f19a3b
data/CHANGELOG.md CHANGED
@@ -5,5 +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
+ ## [1.0.0-beta17] - 2019-07-31
9
+ - Added `rails deimos:db_producer` rake task.
10
+ - Fixed the DB producer so it runs inline instead of on a separate thread.
11
+ Calling code should run it on a thread manually if that is the desired
12
+ behavior.
13
+
8
14
  ## [1.0.0-beta15] - 2019-07-08
9
15
  - Initial release.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deimos-kafka (1.0.0.pre.beta15)
4
+ deimos-kafka (1.0.0.pre.beta17)
5
5
  avro-patches (~> 0.3)
6
6
  avro_turf (~> 0.8)
7
7
  phobos (~> 1.8)
data/README.md CHANGED
@@ -455,6 +455,8 @@ message is first validated, encoded, and saved in the database, and then sent
455
455
  on a separate thread. This means if you have to roll back your transaction,
456
456
  it also rolls back your Kafka messages.
457
457
 
458
+ This is also known as the [Transactional Outbox pattern](https://microservices.io/patterns/data/transactional-outbox.html).
459
+
458
460
  To enable this, first generate the migration to create the relevant tables:
459
461
 
460
462
  rails g deimos:db_backend
@@ -468,12 +470,17 @@ of immediately sending to Kafka. Now, you just need to call
468
470
 
469
471
  Deimos.start_db_backend!
470
472
 
473
+ If using Rails, you can use a Rake task to do this:
474
+
475
+ rails deimos:db_producer
476
+
471
477
  This creates one or more threads dedicated to scanning and publishing these
472
478
  messages by using the `kafka_topics` table in a manner similar to
473
479
  [Delayed Job](https://github.com/collectiveidea/delayed_job).
474
480
  You can pass in a number of threads to the method:
475
481
 
476
- Deimos.start_db_backend!(thread_count: 2)
482
+ Deimos.start_db_backend!(thread_count: 2) # OR
483
+ THREAD_COUNT=5 rails deimos:db_producer
477
484
 
478
485
  If you want to force a message to send immediately, just call the `publish_list`
479
486
  method with `force_send: true`. You can also pass `force_send` into any of the
data/deimos-kafka.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.email = ['daniel.orner@wishabi.com']
12
12
  spec.summary = 'Kafka libraries for Ruby.'
13
13
  spec.homepage = ''
14
- spec.license = 'Apache 2.0'
14
+ spec.license = 'Apache-2.0'
15
15
 
16
16
  spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -83,6 +83,7 @@ module Deimos
83
83
  def phobos_config_changed?(other_config)
84
84
  phobos_keys = %w(seed_broker phobos_config_file ssl_ca_cert ssl_client_cert ssl_client_cert_key)
85
85
  return true if phobos_keys.any? { |key| self.send(key) != other_config.send(key) }
86
+
86
87
  other_config.logger != self.logger
87
88
  end
88
89
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deimos
4
- VERSION = '1.0.0-beta16'
4
+ VERSION = '1.0.0-beta17'
5
5
  end
data/lib/deimos.rb CHANGED
@@ -78,9 +78,13 @@ module Deimos
78
78
  # Start the DB producers to send Kafka messages.
79
79
  # @param thread_count [Integer] the number of threads to start.
80
80
  def start_db_backend!(thread_count: 1)
81
- return if self.config.publish_backend != :db ||
82
- thread_count.nil? ||
83
- thread_count.zero?
81
+ if self.config.publish_backend != :db
82
+ raise("Publish backend is not set to :db, exiting")
83
+ end
84
+
85
+ if thread_count.nil? || thread_count.zero?
86
+ raise("Thread count is not given or set to zero, exiting")
87
+ end
84
88
 
85
89
  producers = (1..thread_count).map do
86
90
  Deimos::Utils::DbProducer.new(self.config.logger)
@@ -88,12 +92,7 @@ module Deimos
88
92
  executor = Deimos::Utils::Executor.new(producers,
89
93
  self.config.logger)
90
94
  signal_handler = Deimos::Utils::SignalHandler.new(executor)
91
- run_db_backend_in_thread(signal_handler)
92
- end
93
-
94
- # @param signal_handler [Deimos::Utils::SignalHandler]
95
- def run_db_backend_in_thread(signal_handler)
96
- Thread.new { signal_handler.run! }
95
+ signal_handler.run!
97
96
  end
98
97
 
99
98
  # @param phobos_config [Hash]
@@ -14,4 +14,14 @@ namespace :deimos do
14
14
  Rails.logger.info('Running deimos:start rake task.')
15
15
  Phobos::CLI::Commands.start(%w(start --skip_config))
16
16
  end
17
+
18
+ desc 'Starts the Deimos database producer'
19
+ task db_producer: :environment do
20
+ ENV['DEIMOS_RAKE_TASK'] = 'true'
21
+ STDOUT.sync = true
22
+ Rails.logger.info("Running deimos:db_producer rake task.")
23
+ thread_count = ENV['THREADS'].presence || 1
24
+ Deimos.start_db_backend!(thread_count: thread_count)
25
+ end
26
+
17
27
  end
data/spec/deimos_spec.rb CHANGED
@@ -73,7 +73,7 @@ describe Deimos do
73
73
 
74
74
  describe '#start_db_backend!' do
75
75
  before(:each) do
76
- allow(described_class).to receive(:run_db_backend_in_thread)
76
+ allow(described_class).to receive(:run_db_backend)
77
77
  end
78
78
 
79
79
  it 'should start if backend is db and num_producer_threads is > 0' do
@@ -94,7 +94,8 @@ describe Deimos do
94
94
  described_class.configure do |config|
95
95
  config.publish_backend = :kafka
96
96
  end
97
- described_class.start_db_backend!(thread_count: 2)
97
+ expect { described_class.start_db_backend!(thread_count: 2) }.
98
+ to raise_error('Publish backend is not set to :db, exiting')
98
99
  end
99
100
 
100
101
  it 'should not start if num_producer_threads is nil' do
@@ -102,7 +103,8 @@ describe Deimos do
102
103
  described_class.configure do |config|
103
104
  config.publish_backend = :db
104
105
  end
105
- described_class.start_db_backend!(thread_count: nil)
106
+ expect { described_class.start_db_backend!(thread_count: nil) }.
107
+ to raise_error('Thread count is not given or set to zero, exiting')
106
108
  end
107
109
 
108
110
  it 'should not start if num_producer_threads is 0' do
@@ -110,7 +112,8 @@ describe Deimos do
110
112
  described_class.configure do |config|
111
113
  config.publish_backend = :db
112
114
  end
113
- described_class.start_db_backend!(thread_count: 0)
115
+ expect { described_class.start_db_backend!(thread_count: 0) }.
116
+ to raise_error('Thread count is not given or set to zero, exiting')
114
117
  end
115
118
 
116
119
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deimos-kafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.beta16
4
+ version: 1.0.0.pre.beta17
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-07-09 00:00:00.000000000 Z
11
+ date: 2019-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro-patches
@@ -398,7 +398,7 @@ files:
398
398
  - support/flipp-logo.png
399
399
  homepage: ''
400
400
  licenses:
401
- - Apache 2.0
401
+ - Apache-2.0
402
402
  metadata: {}
403
403
  post_install_message:
404
404
  rdoc_options: []