message_bus_client_worker 1.2.0 → 1.2.1

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: 0e11858a4762c2a446881b531dc10c0f5d74490a01b61697a3fe9100bf399553
4
- data.tar.gz: 364a0bbdcc1f7a3906ac4a3d2343ab16b7c518afe8fde6a408b6b0b4651f2f73
3
+ metadata.gz: 179ba68462fe0138eee3e10ca73e946a13c33f0a581357f40176b9cedd356202
4
+ data.tar.gz: f1013d26918dd42bbfb8fa54bbefe681f7dc581f1038ba315b5880e6baf71303
5
5
  SHA512:
6
- metadata.gz: 511394ec3c064c50e616625b2ba1baf0b7b05bf047eb75b66110ef9e5132ebb398bffa0cf7f34a308965dca583cd8e2e9bc0fc78db99a8a7df94801337b3928f
7
- data.tar.gz: 65c0a9f3eec5b469fec84450fac71db37d011d261b06ba934bb1ddcc8013579a485d6f5bb801eae6ed43889fb91035117e3813999d16e8186af95f95ffed67a0
6
+ metadata.gz: d1cad80bb3cea5a2561812c64df1bbcece2bdf5c972db229cfe3972f4ec0d5fefb623b61d11d6693fd0706c1d3be8513d4b766627b65eec7c03d3d4af23d7598
7
+ data.tar.gz: 227baabfa7186ebc2297ae5597e251735369f69feec6562e9967d984f0187c4c72f7cae48a485c261f6ff7c7d787691fe8696245e858dc11bd72aeb4cd49b077
@@ -4,6 +4,10 @@ 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
+ ## [1.2.1] - 2019-06-11
8
+ ### Fixed
9
+ - conflicting last id when differentiating with headers
10
+
7
11
  ## [1.2.0] - 2018-02-24
8
12
  ### Added
9
13
  - Add ability to customise client_id
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- message_bus_client_worker (1.2.0)
4
+ message_bus_client_worker (1.2.1)
5
5
  activesupport
6
6
  addressable
7
7
  excon
@@ -12,7 +12,7 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- activesupport (5.2.2)
15
+ activesupport (5.2.3)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (>= 0.7, < 2)
18
18
  minitest (~> 5.1)
@@ -24,12 +24,11 @@ GEM
24
24
  concurrent-ruby (1.0.5)
25
25
  connection_pool (2.2.2)
26
26
  diff-lcs (1.3)
27
- excon (0.62.0)
27
+ excon (0.64.0)
28
28
  gem_config (0.3.1)
29
- i18n (1.5.3)
29
+ i18n (1.6.0)
30
30
  concurrent-ruby (~> 1.0)
31
- light-service (0.11.0)
32
- activesupport (>= 3.0)
31
+ light-service (0.12.0)
33
32
  method_source (0.9.0)
34
33
  minitest (5.11.3)
35
34
  pry (0.11.3)
@@ -38,7 +37,7 @@ GEM
38
37
  pry-byebug (3.6.0)
39
38
  byebug (~> 10.0)
40
39
  pry (~> 0.10)
41
- public_suffix (3.0.3)
40
+ public_suffix (3.1.0)
42
41
  rack (2.0.6)
43
42
  rack-protection (2.0.3)
44
43
  rack
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:
@@ -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"
@@ -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 = "1.2.1"
3
3
  end
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: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramon Tayag
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-24 00:00:00.000000000 Z
11
+ date: 2019-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_config
@@ -221,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
221
  version: '0'
222
222
  requirements: []
223
223
  rubyforge_project:
224
- rubygems_version: 2.7.8
224
+ rubygems_version: 2.7.7
225
225
  signing_key:
226
226
  specification_version: 4
227
227
  summary: Subscribe to MessageBus using Sidekiq workers