railway-ipc 2.0.1 → 2.2.1

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: 11bbf2da076cd07dca74c10a4012cf6e737c7608db72cae9caee418e9188c105
4
- data.tar.gz: b38f426df0aca6a34e18ea7de764d74eaccc183c10fe6af3a04681d7bb658af2
3
+ metadata.gz: 8153f89992dd3713ca4b6e8792a69d91e80738ae69d26bd3325616c30d854bf2
4
+ data.tar.gz: d6680bb1330b885172730f7e9110a255896931d2e627cb50c2b0384cd4a423b2
5
5
  SHA512:
6
- metadata.gz: 3ff4e1f023ad41059c6094f1e6546fac6a4fdc1f4037a4fe9d482327b7b66c23a6db051624ac22338800d52d2c636ec272d01dc853fed22f86d539d7b6fb2333
7
- data.tar.gz: 72f11fcae1cff787ebd8f0a361ff67b81afb1003a8e265d59726a0ee701a35f22b53cd7bddabfb725b6dba217d8fab8da19932594ee9ae1583a508c27083a5d2
6
+ metadata.gz: 404ec939662fbc9f4f8e571b95f3d86222c2d8039afd46346ed10b4319b2f5d8a307d4a0047cc75e041b17393031d0a0551088d2f291d4bf70ecd28baf98b449
7
+ data.tar.gz: efb5cb9aa4635e7d4a07344a61de6bd1f61d39fecbd8445e7baa2d375413603b7e9398cf391feac8b04a7a7c6fc46f5e9cd56791188ed6fb3e233a856a8e1caa
data/.gitignore CHANGED
@@ -8,6 +8,9 @@
8
8
  /tmp/
9
9
  Gemfile.lock
10
10
 
11
+ # built gems
12
+ railway-ipc-*.gem
13
+
11
14
  # rspec failure tracking
12
15
  .rspec_status
13
16
 
@@ -10,6 +10,22 @@ 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
+
13
29
  ## [2.0.1] - 2020-08-24
14
30
  ### Fixed
15
31
  * `RailwayIpc::Logger` now handles block syntax (i.e. `logger.info { 'my message' }`) correctly.
@@ -58,7 +74,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
58
74
  ### Added
59
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)
60
76
 
61
- [Unreleased]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.1...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
62
80
  [2.0.1]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.0...v2.0.1
63
81
  [2.0.0]: https://github.com/learn-co/railway_ipc_gem/compare/v1.1.0...v2.0.0
64
82
  [1.1.0]: https://github.com/learn-co/railway_ipc_gem/compare/v1.0.1...v1.1.0
data/README.md CHANGED
@@ -52,6 +52,26 @@ Then, run your consumers
52
52
  bundle exec rake railway_ipc:consumers:start CONSUMERS=YourConsumer,YourOtherConsumer
53
53
  ```
54
54
 
55
+ You may also configure your consumers more granularly using:
56
+
57
+ `./config/sneaker_worker_groups.yml`
58
+ ```yaml
59
+ HighPriority:
60
+ classes: YourConsumer,YourOtherConsumer
61
+ workers: 5
62
+ LowPriority:
63
+ classes: YourThirdConsumer
64
+ workers: 1
65
+ ```
66
+
67
+ ```bash
68
+ bundle exec rake railway_ipc:consumers:spawn
69
+ ```
70
+
71
+ By default, `spawn` will map to `./config/sneaker_worker_groups.yml` but you can override it by using `WORKER_GROUP_CONFIG`.
72
+
73
+ See the [Sneaker Documentation](https://github.com/jondot/sneakers/wiki/Handling-different-workloads) for more information.
74
+
55
75
  # Request/Response
56
76
 
57
77
  Define your server, client and responder. Docs coming soon.
@@ -2,9 +2,9 @@
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
- require 'railway_ipc/version'
8
8
  require 'railway_ipc/logger'
9
9
  require 'railway_ipc/unhandled_message_error'
10
10
  require 'railway_ipc/response'
@@ -29,12 +29,16 @@ module RailwayIpc
29
29
  Rake::Task['sneakers:run'].invoke
30
30
  end
31
31
 
32
- def self.configure(log_device=STDOUT, level=::Logger::INFO, log_formatter=nil)
32
+ def self.spawn
33
+ Sneakers::Spawner.spawn
34
+ end
35
+
36
+ def self.configure(log_device=$stdout, level=::Logger::INFO, log_formatter=nil)
33
37
  @logger = RailwayIpc::Logger.new(log_device, level, log_formatter)
34
38
  end
35
39
 
36
40
  def self.logger
37
- @logger || RailwayIpc::Logger.new(STDOUT)
41
+ @logger || RailwayIpc::Logger.new($stdout)
38
42
  end
39
43
 
40
44
  def self.bunny_connection
@@ -3,7 +3,10 @@
3
3
  module RailwayIpc
4
4
  class Consumer
5
5
  include Sneakers::Worker
6
+
6
7
  def self.inherited(base)
8
+ super
9
+
7
10
  base.instance_eval do
8
11
  def handlers
9
12
  @handlers ||= RailwayIpc::HandlerStore.new
@@ -11,12 +14,21 @@ module RailwayIpc
11
14
  end
12
15
  end
13
16
 
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
17
+ def self.listen_to(queue:, exchange:, options: {})
18
+ unless options.empty?
19
+ RailwayIpc.logger.info(
20
+ "Overriding configuration for #{queue} with new options",
21
+ feature: 'railway_ipc_consumer',
22
+ options: options
23
+ )
24
+ end
25
+
26
+ from_queue queue, {
27
+ exchange: exchange,
28
+ durable: true,
29
+ exchange_type: :fanout,
30
+ connection: RailwayIpc.bunny_connection
31
+ }.merge(options)
20
32
  end
21
33
 
22
34
  def self.handle(message_type, with:)
@@ -21,7 +21,7 @@ module RailwayIpc
21
21
  # logger = RailwayIpc::Logger.new(STDOUT, Logger::INFO, OjFormatter)
22
22
  #
23
23
  class Logger
24
- def initialize(device=STDOUT, level=::Logger::INFO, formatter=nil)
24
+ def initialize(device=$stdout, level=::Logger::INFO, formatter=nil)
25
25
  @logger = ::Logger.new(device)
26
26
  @logger.level = level
27
27
  @logger.formatter = formatter if formatter
@@ -32,7 +32,7 @@ module RailwayIpc
32
32
  data.merge!(feature: 'railway_ipc') unless data.key?(:feature)
33
33
  return logger.send(level, data.merge(message: message)) unless block
34
34
 
35
- data = message.merge(data) if message&.is_a?(Hash)
35
+ data = message.merge(data) if message.is_a?(Hash)
36
36
  data.merge!(message: block.call)
37
37
 
38
38
  # This is for compatability w/ Ruby's Logger. Ruby's Logger class
@@ -41,7 +41,7 @@ module RailwayIpc
41
41
  # is assumed to be the `progname`.
42
42
  #
43
43
  # https://github.com/ruby/logger/blob/master/lib/logger.rb#L471
44
- data.merge!(progname: message) if message&.is_a?(String)
44
+ data.merge!(progname: message) if message.is_a?(String)
45
45
  logger.send(level, data)
46
46
  end
47
47
  end
@@ -16,7 +16,7 @@ module RailwayIpc
16
16
  :port,
17
17
  :user
18
18
 
19
- def initialize(amqp_url: ENV['RAILWAY_RABBITMQ_CONNECTION_URL'], exchange_name:, queue_name: '', options: {})
19
+ def initialize(exchange_name:, amqp_url: ENV['RAILWAY_RABBITMQ_CONNECTION_URL'], queue_name: '', options: {})
20
20
  @queue_name = queue_name
21
21
  @exchange_name = exchange_name
22
22
  settings = AMQ::Settings.parse_amqp_url(amqp_url)
@@ -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.1'
4
+ VERSION = '2.2.1'
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.1
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-24 00:00:00.000000000 Z
11
+ date: 2020-10-21 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