sidekiq-haron 0.1.6 → 0.2.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: 5923fbd63614f0aa5187a2f36b9f41672ca2187fd5d88bf65a88d62e6327ab04
4
- data.tar.gz: 3764c82c4b824bfdd88b4c8f294183de5d6d44a77649eb03bce8fbfb2088a3c2
3
+ metadata.gz: a903c22b5c1696535db961a28828fa539cebb6695154b4082fb10fd3041f2c53
4
+ data.tar.gz: 9e405c2c5a4e5266d2cd735b13f6dc10c918d35bebda275e690e21b79b491e63
5
5
  SHA512:
6
- metadata.gz: 38d80470789efa5020c68231b285fe4e980ab53ff6eee82b638b3183c7eef5dc887e924da63ddd86c4db317f1d1c564bc25b085e7b521f6ed820637badfa99c8
7
- data.tar.gz: 9a35b3807b96f9d5e40a04d4441a4dbf00630399401d90794c88670fe53a01f9b7d7a673dfd443756e24241a29c3955b245672154c1b740eb4289944ecd6a4aa
6
+ metadata.gz: f3259615f6d5ad26bd53dd1a1f9a934d2f4b1c0ba4099be5062b58dbd103731fff12f0951cac8bc64564d1016b33d721b096980e8419c7f02ab65ab84383dd4a
7
+ data.tar.gz: 5a86580af78520badd3c3a75a9ac4ebb464a7b408b49f497188f82841aa54a41a5a0ce4e1d33b17776954de6e2fdd7d2b38d056d7836c819c1bf04ecf7d5a7c5
data/README.md CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- Аdd to project class inheriting from `Sidekiq::Haron::Transmitter` like this:
23
+ Аdd to project class inheriting from `Sidekiq::Haron::Transmitter` like this:
24
24
 
25
25
  ```ruby
26
26
  class HaronTransmitter < Sidekiq::Haron::Transmitter
@@ -53,9 +53,9 @@ Sidekiq::Haron.install(HaronTransmitter)
53
53
  Now all your sidekiq log have `Current.parent_request_id` value as tag and log job args too:
54
54
 
55
55
  ```
56
- 2020-01-14T14:22:09.035Z TestWorker JID-940645f14b345b3b4031d1cc I: [4f445354] with args [1, {"q"=>2}]
57
- 2020-01-14T14:22:09.035Z TestWorker JID-940645f14b345b3b4031d1cc I: [4f445354] start
58
- 2020-01-14T14:22:09.041Z TestWorker JID-940645f14b345b3b4031d1cc I: [4f445354] done: 0.006 sec
56
+ 2020-01-14T14:22:09.035Z class=TestWorker jid=940645f14b345b3b4031d1cc I: [4f445354] with args [1, {"q"=>2}]
57
+ 2020-01-14T14:22:09.035Z class=TestWorker jid=940645f14b345b3b4031d1cc I: [4f445354] start
58
+ 2020-01-14T14:22:09.041Z class=TestWorker jid=940645f14b345b3b4031d1cc elapsed=0.006 I: [4f445354] done
59
59
  ```
60
60
 
61
61
  ## Development
@@ -1,17 +1,12 @@
1
- require 'sidekiq/exception_handler'
2
1
  module Sidekiq
3
2
  module Haron
4
- class ExceptionLogger < Sidekiq::ExceptionHandler::Logger
3
+ class ExceptionLogger
5
4
 
6
- def self.install
7
- Sidekiq.error_handlers.delete_if{|eh| eh.is_a? Sidekiq::ExceptionHandler::Logger }
8
- Sidekiq.error_handlers.unshift Sidekiq::Haron::ExceptionLogger.new
9
- end
5
+ def call(ex, ctx_hash, config)
6
+ jid = ctx_hash.present? && ctx_hash[:job]['jid']
10
7
 
11
- def call(ex, ctxHash)
12
- jid = ctxHash.present? && ctxHash[:job]['jid']
13
8
  Sidekiq::Haron.transmitter.load(jid) if jid.present?
14
- Sidekiq::Haron.transmitter.tagged{ super(ex, ctxHash) }
9
+ Sidekiq::Haron.transmitter.tagged{ Sidekiq.logger.warn ex.message }
15
10
  end
16
11
 
17
12
  end
@@ -1,16 +1,16 @@
1
1
  module Sidekiq
2
2
  module Haron
3
- class Formatter < Sidekiq::Logging::Pretty
4
-
3
+ class Formatter < Sidekiq::Logger::Formatters::Pretty
4
+
5
5
  def call(severity, time, program_name, message)
6
- result = "#{context} #{severity.to_s[0]}: #{message}\n"
6
+ result = "#{format_context} #{severity.to_s[0]}: #{message}\n"
7
7
  if ENV['RAILS_LOG_TO_STDOUT'].present?
8
8
  result
9
9
  else
10
10
  "#{time.utc.iso8601(3)} #{result}"
11
11
  end
12
12
  end
13
-
13
+
14
14
  end
15
15
  end
16
16
  end
@@ -5,12 +5,12 @@ module Sidekiq
5
5
 
6
6
  def call(item, queue)
7
7
  Sidekiq::Haron.transmitter.load(item['jid'])
8
- Sidekiq::Haron.transmitter.tagged do
8
+ Sidekiq::Haron.transmitter.tagged do
9
9
  Sidekiq.logger.info("with args #{item['args'].inspect}")
10
10
  super
11
11
  end
12
12
  end
13
-
13
+
14
14
  end
15
15
  end
16
16
  end
@@ -8,9 +8,23 @@ module Sidekiq
8
8
 
9
9
  def store_for_id(id, data, redis_pool=nil)
10
10
  redis_connection(redis_pool) do |conn|
11
- conn.multi do
12
- conn.hmset key(id), *(data.to_a.flatten(1))
13
- conn.expire key(id), DEFAULT_EXPIRY
11
+ conn.multi do |pipeline|
12
+ # При попытке записи хэша с полями nil, true, false
13
+ # валится задание с исключением "Unsupported command argument type: NilClass/TrueClass/FalseClass (TypeError)"
14
+ # Пример из консоли Rails (такое же поведение в "бою", данные взяты из реальных кейсов)
15
+ # d = [ :request_id, "9c30943e299135b1fe826d7be6195e78", :parent_request_id, "9c30943e",:user_id, nil ]
16
+ # Sidekiq.redis { |c| c.call('hmset', "kkk", d) }
17
+ # ~/.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
+ # raise TypeError, "Unsupported command argument type: #{element.class}"
19
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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
+ # уход от deprecated-предупреждений внутри sidekiq - нативный вызов hmset для клиента redis
26
+ pipeline.call('hmset', key(id), *(values))
27
+ pipeline.expire key(id), DEFAULT_EXPIRY
14
28
  end[0]
15
29
  end
16
30
  end
@@ -23,8 +23,8 @@ module Sidekiq
23
23
  end
24
24
 
25
25
  def tagged
26
- ::Rails.logger.tagged(tags) do
27
- Sidekiq.logger.tagged(tags) do
26
+ ::Rails.logger.tagged(tags) do
27
+ Sidekiq.logger.tagged(tags) do
28
28
  yield
29
29
  end
30
30
  end
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Haron
3
- VERSION = "0.1.6"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/lib/sidekiq/haron.rb CHANGED
@@ -12,16 +12,16 @@ module Sidekiq
12
12
  module Haron
13
13
 
14
14
  def self.transmitter
15
- Sidekiq.options[:transmitter]
15
+ @transmitter
16
16
  end
17
17
 
18
18
  def self.transmitter= v
19
- Sidekiq.options[:transmitter] = v
19
+ @transmitter = v
20
20
  end
21
21
 
22
- def self.install transmitter_class
22
+ def self.install transmitter_class, with_tagged_logging: true
23
23
  Sidekiq::Haron.transmitter = transmitter_class.new
24
- set_loggers
24
+ set_loggers with_tagged_logging
25
25
  Sidekiq.configure_server do |c|
26
26
  configure_client_middleware(c)
27
27
  configure_server_middleware(c)
@@ -31,11 +31,14 @@ module Sidekiq
31
31
  end
32
32
  end
33
33
 
34
- def self.set_loggers
35
- Sidekiq.options[:job_logger] = Sidekiq::Haron::JobLogger
36
- Sidekiq.logger.formatter = Sidekiq::Haron::Formatter.new
37
- Sidekiq.logger = ActiveSupport::TaggedLogging.new(Sidekiq.logger)
38
- Sidekiq::Haron::ExceptionLogger.install
34
+ def self.set_loggers with_tagged_logging
35
+ Sidekiq.configure_server do |config|
36
+ config.logger.formatter = Sidekiq::Haron::Formatter.new
37
+ config.logger = ActiveSupport::TaggedLogging.new(Sidekiq.logger) if with_tagged_logging
38
+
39
+ config[:job_logger] = Sidekiq::Haron::JobLogger
40
+ config.error_handlers << Sidekiq::Haron::ExceptionLogger.new
41
+ end
39
42
  end
40
43
 
41
44
  def self.configure_client_middleware(sidekiq_config)
@@ -23,10 +23,10 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.add_dependency "sidekiq", "~> 5.2"
27
- spec.add_dependency "rails"
28
- spec.add_development_dependency "bundler", "~> 1.17"
29
- spec.add_development_dependency "rake", "~> 12.3"
26
+ spec.add_dependency "sidekiq", "~> 7.3.0"
27
+ spec.add_dependency "rails", '~> 7.0'
28
+ spec.add_development_dependency "bundler", "~> 2.5.0"
29
+ spec.add_development_dependency "rake", "~> 13.0"
30
30
  spec.add_development_dependency "rspec", "~> 3.0"
31
31
  spec.add_development_dependency "awesome_print"
32
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-haron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serg F
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-28 00:00:00.000000000 Z
11
+ date: 2024-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '5.2'
19
+ version: 7.3.0
20
20
  type: :runtime
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: '5.2'
26
+ version: 7.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '7.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: '0'
40
+ version: '7.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.17'
47
+ version: 2.5.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.17'
54
+ version: 2.5.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '12.3'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '12.3'
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -124,7 +124,7 @@ homepage: https://github.com/Rnd-Soft/sidekiq-haron
124
124
  licenses:
125
125
  - MIT
126
126
  metadata: {}
127
- post_install_message:
127
+ post_install_message:
128
128
  rdoc_options: []
129
129
  require_paths:
130
130
  - lib
@@ -139,8 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  requirements: []
142
- rubygems_version: 3.0.8
143
- signing_key:
142
+ rubygems_version: 3.3.26
143
+ signing_key:
144
144
  specification_version: 4
145
145
  summary: Transfer some data to sidekiq job and can tag sidekiq logs
146
146
  test_files: []