message_bus_client_worker 1.2.0 → 2.1.0

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: 0e11858a4762c2a446881b531dc10c0f5d74490a01b61697a3fe9100bf399553
4
- data.tar.gz: 364a0bbdcc1f7a3906ac4a3d2343ab16b7c518afe8fde6a408b6b0b4651f2f73
3
+ metadata.gz: c4ef20ee860c68da5470850b190d1b9cb5362361d3dbfd27b0bd5f12fbc5390b
4
+ data.tar.gz: 5d481f4e6e10a217494271d47c3a65c02fc91401f13103c98cb169a75ff0b289
5
5
  SHA512:
6
- metadata.gz: 511394ec3c064c50e616625b2ba1baf0b7b05bf047eb75b66110ef9e5132ebb398bffa0cf7f34a308965dca583cd8e2e9bc0fc78db99a8a7df94801337b3928f
7
- data.tar.gz: 65c0a9f3eec5b469fec84450fac71db37d011d261b06ba934bb1ddcc8013579a485d6f5bb801eae6ed43889fb91035117e3813999d16e8186af95f95ffed67a0
6
+ metadata.gz: 849f256761e8c427f7d5e16d7b80928764f41d54e85e6c5711d3bd5e02052b3fb19240b50daa90e854bbba400b83026dcba7d5c39d67f157ad5076c437ad3658
7
+ data.tar.gz: 550137b3cc5fd47f6b19fea9ba784069363e368a0a6f35f68dfd6a48763d7cb94d7f234d7b5ee865df35e4bd085198db12cba0c5384240aa5a25cb2a5757a15e
@@ -0,0 +1,32 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+
21
+ steps:
22
+ - uses: actions/checkout@v2
23
+ - name: Set up Ruby
24
+ uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: 2.7.0
27
+ - name: Start dbs
28
+ run: docker-compose up --detach sidekiq chat
29
+ - name: Copy config
30
+ run: cp spec/config.yml{.sample,}
31
+ - name: Run tests
32
+ run: docker-compose run gem bundle exec rspec spec
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.1
1
+ 2.6.3
data/CHANGELOG.md CHANGED
@@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [2.1.0] - 2021-10-01
8
+ ### Added
9
+ - `MessageBusClientWorker.subscribe(host, config)` which recommended over setting subscriptions via `configure`
10
+
11
+ ## [2.0.0] - 2020-03-12
12
+ ### Changed
13
+ - Update logging in Sidekiq; requires Sidekiq 6
14
+
15
+ ## [1.2.2] - 2020-03-12
16
+ ### Fixed
17
+ - ensure sidekiq `< 6` is installed, since `Sidekiq::Logging` is not available
18
+
19
+ ## [1.2.1] - 2019-06-11
20
+ ### Fixed
21
+ - conflicting last id when differentiating with headers
22
+
7
23
  ## [1.2.0] - 2018-02-24
8
24
  ### Added
9
25
  - Add ability to customise client_id
data/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM ruby:2.5.1
1
+ FROM ruby:2.6.3
2
2
 
3
3
  WORKDIR /gem
4
4
 
@@ -9,7 +9,7 @@ ENV BUNDLE_GEMFILE=/gem/Gemfile \
9
9
  COPY Gemfile Gemfile.lock message_bus_client_worker.gemspec /gem/
10
10
  COPY lib/message_bus_client_worker/version.rb /gem/lib/message_bus_client_worker/
11
11
 
12
- RUN gem install bundler --no-ri --no-rdoc && \
12
+ RUN gem install bundler && \
13
13
  bundle install --jobs 20 --retry 5
14
14
 
15
15
  COPY . /gem
data/Gemfile.lock CHANGED
@@ -1,49 +1,50 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- message_bus_client_worker (1.2.0)
4
+ message_bus_client_worker (2.1.0)
5
5
  activesupport
6
6
  addressable
7
7
  excon
8
8
  gem_config
9
9
  light-service
10
- sidekiq (>= 5.1)
10
+ sidekiq (~> 6.0)
11
11
 
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- activesupport (5.2.2)
15
+ activesupport (6.1.4.1)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
- i18n (>= 0.7, < 2)
18
- minitest (~> 5.1)
19
- tzinfo (~> 1.1)
20
- addressable (2.6.0)
21
- public_suffix (>= 2.0.2, < 4.0)
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ tzinfo (~> 2.0)
20
+ zeitwerk (~> 2.3)
21
+ addressable (2.8.0)
22
+ public_suffix (>= 2.0.2, < 5.0)
22
23
  byebug (10.0.2)
23
24
  coderay (1.1.2)
24
- concurrent-ruby (1.0.5)
25
+ concurrent-ruby (1.1.9)
25
26
  connection_pool (2.2.2)
26
27
  diff-lcs (1.3)
27
- excon (0.62.0)
28
- gem_config (0.3.1)
29
- i18n (1.5.3)
28
+ excon (0.85.0)
29
+ gem_config (0.3.2)
30
+ i18n (1.8.10)
30
31
  concurrent-ruby (~> 1.0)
31
- light-service (0.11.0)
32
- activesupport (>= 3.0)
32
+ light-service (0.17.0)
33
+ activesupport (>= 4.0.0)
33
34
  method_source (0.9.0)
34
- minitest (5.11.3)
35
+ minitest (5.14.4)
35
36
  pry (0.11.3)
36
37
  coderay (~> 1.1.0)
37
38
  method_source (~> 0.9.0)
38
39
  pry-byebug (3.6.0)
39
40
  byebug (~> 10.0)
40
41
  pry (~> 0.10)
41
- public_suffix (3.0.3)
42
- rack (2.0.6)
43
- rack-protection (2.0.3)
42
+ public_suffix (4.0.6)
43
+ rack (2.2.2)
44
+ rack-protection (2.0.8.1)
44
45
  rack
45
46
  rake (10.5.0)
46
- redis (4.0.1)
47
+ redis (4.1.3)
47
48
  rspec (3.7.0)
48
49
  rspec-core (~> 3.7.0)
49
50
  rspec-expectations (~> 3.7.0)
@@ -60,21 +61,20 @@ GEM
60
61
  rspec-core (~> 3.0, >= 3.0.0)
61
62
  sidekiq (>= 2.4.0)
62
63
  rspec-support (3.7.1)
63
- sidekiq (5.1.3)
64
+ sidekiq (6.0.5)
65
+ connection_pool (>= 2.2.2)
66
+ rack (~> 2.0)
67
+ rack-protection (>= 2.0.0)
68
+ redis (>= 4.1.0)
69
+ tzinfo (2.0.4)
64
70
  concurrent-ruby (~> 1.0)
65
- connection_pool (~> 2.2, >= 2.2.0)
66
- rack-protection (>= 1.5.0)
67
- redis (>= 3.3.5, < 5)
68
- thread_safe (0.3.6)
69
- tzinfo (1.2.5)
70
- thread_safe (~> 0.1)
71
71
  wait (0.5.3)
72
+ zeitwerk (2.4.2)
72
73
 
73
74
  PLATFORMS
74
75
  ruby
75
76
 
76
77
  DEPENDENCIES
77
- bundler (~> 1.16)
78
78
  message_bus_client_worker!
79
79
  pry-byebug
80
80
  rake (~> 10.0)
@@ -83,4 +83,4 @@ DEPENDENCIES
83
83
  wait
84
84
 
85
85
  BUNDLED WITH
86
- 1.16.6
86
+ 2.2.28
data/README.md CHANGED
@@ -7,6 +7,8 @@ Subscribe to [MessageBus](https://github.com/SamSaffron/message_bus) using Sidek
7
7
  - do not unnecessarily add noise when starting the console like `rails console`
8
8
  - recover from downtime by keeping track of the last message it processed per channel
9
9
 
10
+ This gem does **not** promise that the message are processed only once. You must put safeguards in place if it is imperative that messages are not processed more than once.
11
+
10
12
  ## Installation
11
13
 
12
14
  Add this line to your application's Gemfile:
@@ -32,10 +34,15 @@ MessageBusClientWorker.configure do |c|
32
34
  c.subscriptions = {
33
35
  # Format is
34
36
  # "https://domain.com" => {
35
- # "/a_channel" => {
36
- # processor: "ProcessorClass",
37
- # message_id: 0,
38
- # }
37
+ # headers: {
38
+ # "Some header" => "only if you want",
39
+ # },
40
+ # channels: {
41
+ # "/a_channel" => {
42
+ # processor: "ProcessorClass",
43
+ # message_id: 0,
44
+ # }
45
+ # },
39
46
  # }
40
47
  "https://etc.com" => {
41
48
  headers: {
data/docker-compose.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  version: "3.2"
2
2
  services:
3
3
  redis:
4
- image: redis:4.0.10
4
+ image: redis:5.0.7
5
5
  ports:
6
6
  - "6379:6379"
7
7
  gem:
@@ -2,8 +2,13 @@ module MessageBusClientWorker
2
2
  module Polling
3
3
  class GenLastIdKey
4
4
 
5
- def self.call(host, channel)
6
- [host, channel].join("-")
5
+ def self.call(host:, channel:, headers: {})
6
+ key_parts = [host, channel]
7
+ (headers || {}).each do |key, value|
8
+ key_parts << [key, value].join("_")
9
+ end
10
+
11
+ Digest::SHA256.hexdigest(key_parts.join("-"))
7
12
  end
8
13
 
9
14
  end
@@ -3,7 +3,7 @@ module MessageBusClientWorker
3
3
  class GenerateParams
4
4
  extend LightService::Action
5
5
 
6
- expects :host, :subscriptions
6
+ expects :host, :subscriptions, :headers
7
7
  promises :params, :form_params
8
8
 
9
9
  DEFAULT_MESSAGE_ID = "-1".freeze
@@ -13,8 +13,16 @@ module MessageBusClientWorker
13
13
 
14
14
  c.params = { dlp: 't' }
15
15
  c.form_params = channels.each_with_object({}) do |sub, hash|
16
+ channel = sub[0]
16
17
  custom_message_id = sub[1][:message_id] ? sub[1][:message_id].to_s : nil
17
- hash[sub[0]] = GetLastId.(c.host, sub[0]) ||
18
+
19
+ last_id_in_memory = GetLastId.(
20
+ host: c.host,
21
+ channel: channel,
22
+ headers: c.headers,
23
+ )
24
+
25
+ hash[channel] = last_id_in_memory ||
18
26
  custom_message_id ||
19
27
  DEFAULT_MESSAGE_ID
20
28
  end
@@ -2,8 +2,8 @@ module MessageBusClientWorker
2
2
  module Polling
3
3
  class GetLastId
4
4
 
5
- def self.call(host, channel)
6
- hash_key = GenLastIdKey.(host, channel)
5
+ def self.call(host:, channel:, headers: {})
6
+ hash_key = GenLastIdKey.(host: host, channel: channel, headers: headers)
7
7
  Sidekiq.redis { |r| r.hget(SetLastId::CHANNEL_INDICES_NAME, hash_key) }
8
8
  end
9
9
 
@@ -21,7 +21,12 @@ module MessageBusClientWorker
21
21
  next c if channel_config.nil?
22
22
 
23
23
  processor_class = Kernel.const_get(channel_config[:processor])
24
- SetLastId.(c.host, channel, payload["message_id"])
24
+ SetLastId.(
25
+ host: c.host,
26
+ channel: channel,
27
+ message_id: payload["message_id"],
28
+ headers: c.headers,
29
+ )
25
30
 
26
31
  data = payload["data"]
27
32
 
@@ -3,8 +3,8 @@ module MessageBusClientWorker
3
3
  class SetLastId
4
4
 
5
5
  CHANNEL_INDICES_NAME = "message_bus_client_worker_channel_indices".freeze
6
- def self.call(host, channel, message_id)
7
- hash_key = GenLastIdKey.(host, channel)
6
+ def self.call(host:, channel:, message_id:, headers:)
7
+ hash_key = GenLastIdKey.(host: host, channel: channel, headers: headers)
8
8
 
9
9
  id = Sidekiq.redis do |r|
10
10
  r.hset(CHANNEL_INDICES_NAME, hash_key, message_id)
@@ -1,3 +1,3 @@
1
1
  module MessageBusClientWorker
2
- VERSION = "1.2.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -13,7 +13,7 @@ module MessageBusClientWorker
13
13
 
14
14
  def log(host, subscriptions)
15
15
  subscriptions[:channels].each do |channel, _|
16
- Sidekiq::Logging.logger.info "Enqueued #{host} for #{channel}"
16
+ logger.info "Enqueued #{host} for #{channel}"
17
17
  end
18
18
  end
19
19
 
@@ -1,4 +1,5 @@
1
1
  require "addressable"
2
+ require "digest"
2
3
  require "excon"
3
4
  require "gem_config"
4
5
  require "light-service"
@@ -25,8 +26,18 @@ module MessageBusClientWorker
25
26
  include GemConfig::Base
26
27
 
27
28
  with_configuration do
28
- has :subscriptions, classes: Hash
29
+ has :subscriptions, classes: [Hash, NilClass]
29
30
  has :client_id, classes: [Proc, String], default: -> {SecureRandom.uuid}
30
31
  end
31
32
 
33
+ def self.subscribe(host, options)
34
+ self.configuration.subscriptions ||= {}
35
+
36
+ if self.configuration.subscriptions.keys.include?(host)
37
+ warn "[#{self.name}] #{host} already configured, overwriting (called from #{caller.first})"
38
+ end
39
+
40
+ self.configuration.subscriptions[host] = options
41
+ end
42
+
32
43
  end
@@ -31,13 +31,12 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  spec.add_dependency "gem_config"
34
- spec.add_dependency "sidekiq", ">= 5.1"
34
+ spec.add_dependency "sidekiq", "~> 6.0"
35
35
  spec.add_dependency "excon"
36
36
  spec.add_dependency "addressable"
37
37
  spec.add_dependency "light-service"
38
38
  spec.add_dependency "activesupport"
39
39
 
40
- spec.add_development_dependency "bundler", "~> 1.16"
41
40
  spec.add_development_dependency "rake", "~> 10.0"
42
41
  spec.add_development_dependency "rspec", "~> 3.0"
43
42
  spec.add_development_dependency "rspec-sidekiq"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: message_bus_client_worker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramon Tayag
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-24 00:00:00.000000000 Z
11
+ date: 2021-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_config
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: sidekiq
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.1'
33
+ version: '6.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.1'
40
+ version: '6.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: excon
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,20 +94,6 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: bundler
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '1.16'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '1.16'
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: rake
113
99
  requirement: !ruby/object:Gem::Requirement
@@ -164,17 +150,17 @@ dependencies:
164
150
  - - ">="
165
151
  - !ruby/object:Gem::Version
166
152
  version: '0'
167
- description:
153
+ description:
168
154
  email:
169
155
  - ramon.tayag@gmail.com
170
156
  executables: []
171
157
  extensions: []
172
158
  extra_rdoc_files: []
173
159
  files:
160
+ - ".github/workflows/ruby.yml"
174
161
  - ".gitignore"
175
162
  - ".rspec"
176
163
  - ".ruby-version"
177
- - ".travis.yml"
178
164
  - CHANGELOG.md
179
165
  - CODE_OF_CONDUCT.md
180
166
  - Dockerfile
@@ -205,7 +191,7 @@ licenses:
205
191
  - MIT
206
192
  metadata:
207
193
  allowed_push_host: https://rubygems.org
208
- post_install_message:
194
+ post_install_message:
209
195
  rdoc_options: []
210
196
  require_paths:
211
197
  - lib
@@ -220,9 +206,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
206
  - !ruby/object:Gem::Version
221
207
  version: '0'
222
208
  requirements: []
223
- rubyforge_project:
224
- rubygems_version: 2.7.8
225
- signing_key:
209
+ rubygems_version: 3.1.6
210
+ signing_key:
226
211
  specification_version: 4
227
212
  summary: Subscribe to MessageBus using Sidekiq workers
228
213
  test_files: []
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.5.1
5
- before_script:
6
- - cp spec/config.yml{.sample,}
7
- - docker-compose up -d sidekiq chat
8
- script: docker-compose run gem bundle exec rspec spec