sidekiq-haron 0.2.0 → 0.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: a903c22b5c1696535db961a28828fa539cebb6695154b4082fb10fd3041f2c53
4
- data.tar.gz: 9e405c2c5a4e5266d2cd735b13f6dc10c918d35bebda275e690e21b79b491e63
3
+ metadata.gz: 8f5183320211a90551c5039db8d82d9ce81fc73e71bd8b63d5fe99cbc058112d
4
+ data.tar.gz: 071d956d8686ad05ac533f43dee401699d0af01aa2b0bc95ba0257492521548a
5
5
  SHA512:
6
- metadata.gz: f3259615f6d5ad26bd53dd1a1f9a934d2f4b1c0ba4099be5062b58dbd103731fff12f0951cac8bc64564d1016b33d721b096980e8419c7f02ab65ab84383dd4a
7
- data.tar.gz: 5a86580af78520badd3c3a75a9ac4ebb464a7b408b49f497188f82841aa54a41a5a0ce4e1d33b17776954de6e2fdd7d2b38d056d7836c819c1bf04ecf7d5a7c5
6
+ metadata.gz: 3877e4559a59169c84f9bbd7d9ccd58c3e352b5b51d2a9f8d708947c83082648464254d9e12db58690ef3514fda0753831f8adc9a7558abd54417c58b5b3cc67
7
+ data.tar.gz: 9b1f60f69fd371a591c6fff173d64e11be3a0abe82a29cf07d63de7a102245749637d0188fa2f5dad0edf3ab68688ccd2a5de5eaff07b134c393973aca25087f
@@ -0,0 +1,42 @@
1
+ module Sidekiq
2
+ module Haron
3
+ module Storage
4
+ module RedisConverts
5
+ # Введена интерпретация значений nil, true, false в связи с возникающими ошибками:
6
+ # nil - 'NilClass'
7
+ # true - 'TrueClass'
8
+ # false - 'FalseClass'
9
+
10
+ CLASSES_TO_CONVERT = { NilClass => {redis_value: 'NilClass', orig_value: nil},
11
+ TrueClass => {redis_value: 'TrueClass', orig_value: true},
12
+ FalseClass => {redis_value: 'FalseClass', orig_value: false} }.freeze
13
+
14
+ def encode_values_from array
15
+ return array unless array.is_a?(Array)
16
+
17
+ array.map do |value|
18
+ CLASSES_TO_CONVERT.keys.include?(value.class) ? CLASSES_TO_CONVERT[value.class][:redis_value] : value
19
+ end
20
+ end
21
+
22
+ def decode_values_from hash
23
+ return hash unless hash.is_a?(Hash)
24
+
25
+ hash.transform_values do |value|
26
+ key = key_by_redis_value(value)
27
+ value = key.nil? ? value : CLASSES_TO_CONVERT[key][:orig_value]
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def key_by_redis_value redis_value
34
+ CLASSES_TO_CONVERT.each do |k, v|
35
+ return k if v[:redis_value] == redis_value
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+ end
@@ -2,6 +2,8 @@ module Sidekiq
2
2
  module Haron
3
3
  module Storage
4
4
 
5
+ include RedisConverts
6
+
5
7
  DEFAULT_EXPIRY = 7 * 24 * 60 * 60 # 7 days
6
8
 
7
9
  protected
@@ -17,13 +19,8 @@ module Sidekiq
17
19
  # ~/.rvm/gems/ruby-3.3.5/gems/irb-1.14.1/lib/irb.rb:1260:in `full_message': Unsupported command argument type: NilClass (TypeError)
18
20
  # raise TypeError, "Unsupported command argument type: #{element.class}"
19
21
  # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20
- # Потому введена интерпретация значений:
21
- # nil - ''
22
- # true - 1
23
- # false - 0
24
- values = data.to_a.flatten(1).map{ |each| each.nil? ? '' : each }.map{ |each| each == true ? 1 : (each == false ? 0 : each) }
25
22
  # уход от deprecated-предупреждений внутри sidekiq - нативный вызов hmset для клиента redis
26
- pipeline.call('hmset', key(id), *(values))
23
+ pipeline.call('hmset', key(id), *(encode_values_from data.to_a.flatten(1)))
27
24
  pipeline.expire key(id), DEFAULT_EXPIRY
28
25
  end[0]
29
26
  end
@@ -31,7 +28,7 @@ module Sidekiq
31
28
 
32
29
  def read_for_id(id)
33
30
  Sidekiq.redis do |conn|
34
- conn.hgetall(key(id))
31
+ decode_values_from conn.hgetall(key(id))
35
32
  end
36
33
  end
37
34
 
@@ -23,12 +23,15 @@ module Sidekiq
23
23
  end
24
24
 
25
25
  def tagged
26
- ::Rails.logger.tagged(tags) do
27
- Sidekiq.logger.tagged(tags) do
28
- yield
26
+ if ::Rails.logger.respond_to?(:tagged) && Sidekiq.logger.respond_to?(:tagged)
27
+ ::Rails.logger.tagged(tags) do
28
+ Sidekiq.logger.tagged(tags) do
29
+ yield
30
+ end
29
31
  end
32
+ else
33
+ yield
30
34
  end
31
-
32
35
  end
33
36
 
34
37
  def tags
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Haron
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1".freeze
4
4
  end
5
5
  end
data/lib/sidekiq/haron.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'sidekiq'
2
2
  require 'sidekiq/haron/formatter'
3
+ require 'sidekiq/haron/redis_converts'
3
4
  require 'sidekiq/haron/storage'
4
5
  require 'sidekiq/haron/transmitter'
5
6
  require 'sidekiq/haron/job_logger'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-haron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serg F
@@ -115,6 +115,7 @@ files:
115
115
  - lib/sidekiq/haron/exception_logger.rb
116
116
  - lib/sidekiq/haron/formatter.rb
117
117
  - lib/sidekiq/haron/job_logger.rb
118
+ - lib/sidekiq/haron/redis_converts.rb
118
119
  - lib/sidekiq/haron/server_middleware.rb
119
120
  - lib/sidekiq/haron/storage.rb
120
121
  - lib/sidekiq/haron/transmitter.rb