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 +4 -4
- data/lib/sidekiq/haron/redis_converts.rb +42 -0
- data/lib/sidekiq/haron/storage.rb +4 -7
- data/lib/sidekiq/haron/transmitter.rb +7 -4
- data/lib/sidekiq/haron/version.rb +1 -1
- data/lib/sidekiq/haron.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f5183320211a90551c5039db8d82d9ce81fc73e71bd8b63d5fe99cbc058112d
|
4
|
+
data.tar.gz: 071d956d8686ad05ac533f43dee401699d0af01aa2b0bc95ba0257492521548a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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), *(
|
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(
|
27
|
-
|
28
|
-
|
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
|
data/lib/sidekiq/haron.rb
CHANGED
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.
|
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
|