railway-ipc 2.0.0 → 2.2.0

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: 11e49c11ff3e5815f7c8050ad5fcdfde1510cf7646d10cfa5d1104a5c1868422
4
- data.tar.gz: 3fbdeab2e555f9c4b3402cf27e3b072d33c833f85659eaccc09f31d11fddc219
3
+ metadata.gz: ade6188ad53835d058964953332583db7cf146f2b02b58c4a25cddb42e7f89cf
4
+ data.tar.gz: 4672c6b08a293c1988f42c944063cc9ba67d6656531b8c3a3fd9b00ab908219e
5
5
  SHA512:
6
- metadata.gz: 70d3834ac2a0db7b1a9a53c52edb3718b34a821d3b0d42e49ebe01f1c76c00188b928734a5969ef621e9609a3852117fd8190706566777c870b2b8b3d9592ccd
7
- data.tar.gz: 297bbf2e92f9a77d85661849f3bbada5b18eff08b213ec6a48089dea112ab65b70a47b196e8ddc59b475e61cb9e6ecfc8648bb5dcbcd2836e341079d81b2fd92
6
+ metadata.gz: a76acd180339079bc95bd042e6a6c2512edd05d485ca2763e8211278f85adf0677156f1e8d305ce5cc4186c9304ed85e7c8343b0a32b79560225e1261e7801a9
7
+ data.tar.gz: ceab6497161f8c640cbb2da715b9380729b1e8dbb40843d11fd879a32214e7f39f5aa130d811eeff66c0f0b59eea743e6cb97aa8fb89bcb2fa62aa06ceffb65f
@@ -10,6 +10,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
  ### Removed
11
11
  ### Fixed
12
12
 
13
+ ## [2.2.0] - 2020-10-20
14
+ ### Added
15
+ * The ability to configure workers to handle different workloads via `rake railway_ipc::consumers:spawn`
16
+
17
+ ## [2.1.0] - 2020-10-19
18
+ ### Added
19
+ * :options parameter to `listen_to` which passes keys along to Sneaker's `from_queue` method.
20
+
21
+ ## [2.0.3] - 2020-09-02
22
+ ### Fixed
23
+ * Fix RPC server. RPC servers need to conform to the Sneaker worker API (i.e. their initializers need to be able to accept queue name / pool and they require a `stop` method.
24
+
25
+ ## [2.0.2] - 2020-08-27
26
+ ### Changed
27
+ * RPC `RailwayIpc::Client` does not need to log the queue name.
28
+
29
+ ## [2.0.1] - 2020-08-24
30
+ ### Fixed
31
+ * `RailwayIpc::Logger` now handles block syntax (i.e. `logger.info { 'my message' }`) correctly.
32
+
13
33
  ## [2.0.0] - 2020-08-20
14
34
  ### Added
15
35
  * Several additions to internal logging:
@@ -54,7 +74,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
54
74
  ### Added
55
75
  - Correlation ID and message UUID are auto generated for messages for IDs are not passed in [#23](https://github.com/learn-co/railway_ipc_gem/pull/23)
56
76
 
57
- [Unreleased]: https://github.com/learn-co/railway_ipc_gem/compare/v1.1.0...HEAD
77
+ [Unreleased]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.3...HEAD
78
+ [2.0.3]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.2...v2.0.3
79
+ [2.0.2]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.1...v2.0.2
80
+ [2.0.1]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.0...v2.0.1
81
+ [2.0.0]: https://github.com/learn-co/railway_ipc_gem/compare/v1.1.0...v2.0.0
58
82
  [1.1.0]: https://github.com/learn-co/railway_ipc_gem/compare/v1.0.1...v1.1.0
59
83
  [1.0.1]: https://github.com/learn-co/railway_ipc_gem/compare/v1.0.0...v1.0.1
60
84
  [1.0.0]: https://github.com/learn-co/railway_ipc_gem/compare/v0.1.7...v1.0.0
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'railway_ipc/version'
4
4
  require 'sneakers'
5
+ require 'sneakers/spawner'
5
6
  require 'bunny'
6
7
  require 'active_record'
7
8
  require 'railway_ipc/version'
@@ -29,6 +30,10 @@ module RailwayIpc
29
30
  Rake::Task['sneakers:run'].invoke
30
31
  end
31
32
 
33
+ def self.spawn
34
+ Sneakers::Spawner.spawn
35
+ end
36
+
32
37
  def self.configure(log_device=STDOUT, level=::Logger::INFO, log_formatter=nil)
33
38
  @logger = RailwayIpc::Logger.new(log_device, level, log_formatter)
34
39
  end
@@ -3,6 +3,7 @@
3
3
  module RailwayIpc
4
4
  class Consumer
5
5
  include Sneakers::Worker
6
+
6
7
  def self.inherited(base)
7
8
  base.instance_eval do
8
9
  def handlers
@@ -11,12 +12,13 @@ module RailwayIpc
11
12
  end
12
13
  end
13
14
 
14
- def self.listen_to(queue:, exchange:)
15
- from_queue queue,
16
- exchange: exchange,
17
- durable: true,
18
- exchange_type: :fanout,
19
- connection: RailwayIpc.bunny_connection
15
+ def self.listen_to(queue:, exchange:, options: {})
16
+ from_queue queue, {
17
+ exchange: exchange,
18
+ durable: true,
19
+ exchange_type: :fanout,
20
+ connection: RailwayIpc.bunny_connection
21
+ }.merge(options)
20
22
  end
21
23
 
22
24
  def self.handle(message_type, with:)
@@ -28,9 +28,21 @@ module RailwayIpc
28
28
  end
29
29
 
30
30
  %w[fatal error warn info debug].each do |level|
31
- define_method(level) do |message, data={}|
31
+ define_method(level) do |message=nil, data={}, &block|
32
32
  data.merge!(feature: 'railway_ipc') unless data.key?(:feature)
33
- logger.send(level, data.merge(message: message))
33
+ return logger.send(level, data.merge(message: message)) unless block
34
+
35
+ data = message.merge(data) if message&.is_a?(Hash)
36
+ data.merge!(message: block.call)
37
+
38
+ # This is for compatability w/ Ruby's Logger. Ruby's Logger class
39
+ # assumes that if both a `message` argument and a block are given,
40
+ # that the block contains the actual message. The `message` argument
41
+ # is assumed to be the `progname`.
42
+ #
43
+ # https://github.com/ruby/logger/blob/master/lib/logger.rb#L471
44
+ data.merge!(progname: message) if message&.is_a?(String)
45
+ logger.send(level, data)
34
46
  end
35
47
  end
36
48
 
@@ -39,7 +39,6 @@ module RailwayIpc
39
39
  end
40
40
 
41
41
  # rubocop:disable Metrics/AbcSize
42
- # rubocop:disable Metrics/MethodLength
43
42
  def process_payload(response)
44
43
  decoded_payload = decode_payload(response)
45
44
  case decoded_payload.type
@@ -49,7 +48,6 @@ module RailwayIpc
49
48
  'Handling response',
50
49
  feature: 'railway_ipc_consumer',
51
50
  exchange: self.class.exchange_name,
52
- queue: self.class.queue_name,
53
51
  protobuf: { type: message.class, data: message }
54
52
  )
55
53
  RailwayIpc::Response.new(message, success: true)
@@ -58,7 +56,6 @@ module RailwayIpc
58
56
  raise RailwayIpc::UnhandledMessageError.new("#{self.class} does not know how to handle #{decoded_payload.type}")
59
57
  end
60
58
  end
61
- # rubocop:enable Metrics/MethodLength
62
59
  # rubocop:enable Metrics/AbcSize
63
60
 
64
61
  def setup_rabbit_connection
@@ -90,7 +87,6 @@ module RailwayIpc
90
87
  exception.message,
91
88
  feature: 'railway_ipc_consumer',
92
89
  exchange: self.class.exchange_name,
93
- queue: self.class.queue_name,
94
90
  error: exception.class,
95
91
  payload: decode_for_error(exception, payload)
96
92
  )
@@ -3,7 +3,7 @@
3
3
  module RailwayIpc
4
4
  module RPC
5
5
  module MessageObservationConfigurable
6
- def listen_to(exchange:, queue:)
6
+ def listen_to(queue:, exchange:)
7
7
  @exchange_name = exchange
8
8
  @queue_name = queue
9
9
  end
@@ -14,7 +14,7 @@ module RailwayIpc
14
14
  RailwayIpc::RPC::ServerResponseHandlers.instance.register(handler: with, message: message_type)
15
15
  end
16
16
 
17
- def initialize(opts={ automatic_recovery: true }, rabbit_adapter: RailwayIpc::Rabbitmq::Adapter)
17
+ def initialize(_queue, _pool, opts={ automatic_recovery: true }, rabbit_adapter: RailwayIpc::Rabbitmq::Adapter)
18
18
  @rabbit_connection = rabbit_adapter.new(
19
19
  queue_name: self.class.queue_name,
20
20
  exchange_name: self.class.exchange_name,
@@ -31,6 +31,10 @@ module RailwayIpc
31
31
  subscribe_to_queue
32
32
  end
33
33
 
34
+ def stop
35
+ rabbit_connection.disconnect
36
+ end
37
+
34
38
  # rubocop:disable Metrics/AbcSize
35
39
  # rubocop:disable Metrics/MethodLength
36
40
  def work(payload)
@@ -2,9 +2,15 @@
2
2
 
3
3
  namespace :railway_ipc do
4
4
  namespace :consumers do
5
+ desc 'Start consumers via explicitly defining them'
5
6
  task :start do
6
7
  ENV['WORKERS'] = ENV['CONSUMERS']
7
8
  RailwayIpc.start
8
9
  end
10
+
11
+ desc 'Start consumers via ./config/sneaker_worker_groups.yml'
12
+ task :spawn do
13
+ RailwayIpc.spawn
14
+ end
9
15
  end
10
16
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailwayIpc
4
- VERSION = '2.0.0'
4
+ VERSION = '2.2.0'
5
5
  end
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
35
  spec.require_paths = ['lib']
36
36
 
37
- spec.add_development_dependency 'bundler', '2.0.1'
37
+ spec.add_development_dependency 'bundler', '2.1.4'
38
38
  spec.add_development_dependency 'factory_bot', '~> 5.1'
39
39
  spec.add_development_dependency 'google-protobuf', '~> 3.9'
40
40
  spec.add_development_dependency 'rake', '>= 10.0.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railway-ipc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-20 00:00:00.000000000 Z
11
+ date: 2020-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.1
19
+ version: 2.1.4
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.1
26
+ version: 2.1.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: factory_bot
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -278,8 +278,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
278
278
  - !ruby/object:Gem::Version
279
279
  version: '0'
280
280
  requirements: []
281
- rubyforge_project:
282
- rubygems_version: 2.7.6
281
+ rubygems_version: 3.0.3
283
282
  signing_key:
284
283
  specification_version: 4
285
284
  summary: IPC components for Rails