checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 22cd74baefe621ddce19baf896d194862eb7b5dc707fa0df8b3293856f4f2ce4
4
+ data.tar.gz: 10f78860a68ccba3f377f3d40caa5c7ca22d1c39272d972d6f9c70b9510cceb1
5
+ SHA512:
6
+ metadata.gz: 11322d38ec911fe423c137f16dd5fe7c180950f302d921690a120020e6d6a4d1c9ad39915d158d3e234480d0a671e49d0be6f36ba61567741187b9805c2f7847
7
+ data.tar.gz: 5f00881f12f9aea5aace610b43ce9e0c6b5d9dc189dcfa8cd713a339dc08daf7e2217b2afdd4a24950ddc3243e29c1d3a65f85c667669d93e8ddf55a4357c672
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in sidekiq-haron.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Serg F
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Sidekiq::Haron
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sidekiq/haron`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sidekiq-haron'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sidekiq-haron
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sidekiq-haron.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/lib/sidekiq/haron.rb ADDED
@@ -0,0 +1,52 @@
1
+ require 'sidekiq/haron/formatter'
2
+ require 'sidekiq/haron/storage'
3
+ require 'sidekiq/haron/transmitter'
4
+ require 'sidekiq/haron/job_logger'
5
+ require 'sidekiq/haron/exception_logger'
6
+ require 'sidekiq/haron/client_middleware'
7
+ require 'sidekiq/haron/server_middleware'
8
+ require 'sidekiq/haron/version'
9
+
10
+ module Sidekiq
11
+ module Haron
12
+
13
+ mattr_accessor :transmitter
14
+
15
+ def self.install transmitter_class
16
+ Sidekiq::Haron.transmitter = transmitter_class.new
17
+ set_loggers
18
+ Sidekiq.configure_server do |c|
19
+ configure_client_middleware(c)
20
+ configure_server_middleware(c)
21
+ end
22
+ Sidekiq.configure_client do |c|
23
+ configure_client_middleware(c)
24
+ end
25
+ end
26
+
27
+ def self.set_loggers
28
+ Sidekiq.options[:job_logger] = Sidekiq::Haron::JobLogger
29
+ Sidekiq.logger.formatter = Sidekiq::Haron::Formatter.new
30
+ Sidekiq.logger = ActiveSupport::TaggedLogging.new(Sidekiq.logger)
31
+ Sidekiq::Haron::ExceptionLogger.install
32
+ end
33
+
34
+ def self.configure_client_middleware(sidekiq_config)
35
+ sidekiq_config.client_middleware do |chain|
36
+ chain.add Sidekiq::Haron::ClientMiddleware
37
+ end
38
+ end
39
+
40
+ def self.configure_server_middleware(sidekiq_config)
41
+ sidekiq_config.server_middleware do |chain|
42
+ if Sidekiq.major_version < 5
43
+ chain.insert_after Sidekiq::Middleware::Server::Logging,
44
+ Sidekiq::Haron::ServerMiddleware
45
+ else
46
+ chain.add Sidekiq::Haron::ServerMiddleware
47
+ end
48
+ end
49
+ end
50
+
51
+ end
52
+ end
data/lib/sidekiq/haron/client_middleware.rb ADDED
@@ -0,0 +1,10 @@
1
+ class Sidekiq::Haron::ClientMiddleware
2
+
3
+ def call(worker_class, msg, queue, redis_pool=nil)
4
+ if msg['retry_count'].blank? # don't store on retry
5
+ Sidekiq::Haron.transmitter.save(worker_class, msg, queue, redis_pool)
6
+ end
7
+ yield
8
+ end
9
+
10
+ end
data/lib/sidekiq/haron/exception_logger.rb ADDED
@@ -0,0 +1,14 @@
1
+ class Sidekiq::Haron::ExceptionLogger < Sidekiq::ExceptionHandler::Logger
2
+
3
+ def self.install
4
+ Sidekiq.error_handlers.delete_if{|eh| eh.is_a? Sidekiq::ExceptionHandler::Logger }
5
+ Sidekiq.error_handlers.unshift Sidekiq::Haron::ExceptionLogger.new
6
+ end
7
+
8
+ def call(ex, ctxHash)
9
+ jid = ctxHash.present? && ctxHash[:job]['jid']
10
+ Sidekiq::Haron.transmitter.load(jid) if jid.present?
11
+ Sidekiq::Haron.transmitter.tagged{ super(ex, ctxHash) }
12
+ end
13
+
14
+ end
data/lib/sidekiq/haron/formatter.rb ADDED
@@ -0,0 +1,12 @@
1
+ class Sidekiq::Haron::Formatter < Sidekiq::Logging::Pretty
2
+
3
+ def call(severity, time, program_name, message)
4
+ result = "#{context} #{severity.to_s[0]}: #{message}\n"
5
+ if ENV['RAILS_LOG_TO_STDOUT'].present?
6
+ result
7
+ else
8
+ "#{time.utc.iso8601(3)} #{result}"
9
+ end
10
+ end
11
+
12
+ end
data/lib/sidekiq/haron/job_logger.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'sidekiq/job_logger'
2
+ class Sidekiq::Haron::JobLogger < Sidekiq::JobLogger
3
+
4
+ def call(item, queue)
5
+ Sidekiq::Haron.transmitter.load(item['jid'])
6
+ Sidekiq::Haron.transmitter.tagged do
7
+ Sidekiq.logger.info("with args #{item['args'].inspect}")
8
+ super
9
+ end
10
+ end
11
+
12
+ end
data/lib/sidekiq/haron/server_middleware.rb ADDED
@@ -0,0 +1,8 @@
1
+ class Sidekiq::Haron::ServerMiddleware
2
+
3
+ def call(worker, msg, queue)
4
+ Sidekiq::Haron.transmitter.load(msg['jid'])
5
+ yield
6
+ end
7
+
8
+ end
data/lib/sidekiq/haron/storage.rb ADDED
@@ -0,0 +1,38 @@
1
+ module Sidekiq::Haron::Storage
2
+ DEFAULT_EXPIRY = 30 * 24 * 60 * 60 # 30 days
3
+
4
+ protected
5
+
6
+ def store_for_id(id, data, redis_pool=nil)
7
+ redis_connection(redis_pool) do |conn|
8
+ conn.multi do
9
+ conn.hmset key(id), *(data.to_a.flatten(1))
10
+ conn.expire key(id), DEFAULT_EXPIRY
11
+ end[0]
12
+ end
13
+ end
14
+
15
+ def read_for_id(id)
16
+ Sidekiq.redis do |conn|
17
+ conn.hgetall(key(id))
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def redis_connection(redis_pool=nil)
24
+ if redis_pool
25
+ redis_pool.with do |conn|
26
+ yield conn
27
+ end
28
+ else
29
+ Sidekiq.redis do |conn|
30
+ yield conn
31
+ end
32
+ end
33
+ end
34
+
35
+ def key(id)
36
+ "sidekiq:haron:#{id}"
37
+ end
38
+ end
data/lib/sidekiq/haron/transmitter.rb ADDED
@@ -0,0 +1,39 @@
1
+ class Sidekiq::Haron::Transmitter
2
+ include Sidekiq::Haron::Storage
3
+
4
+ def save worker_class, msg, queue, redis_pool
5
+ data = saved_data(worker_class, msg, queue)
6
+ store_for_id msg['jid'], data, redis_pool
7
+ end
8
+
9
+ def load jid
10
+ load_data read_for_id(jid)
11
+ rescue => e
12
+ Sidekiq.logger.error "loading data error - #{e.to_s}"
13
+ {}
14
+ end
15
+
16
+ def tagged
17
+ Rails.logger.tagged(tags) do
18
+ Sidekiq.logger.tagged(tags) do
19
+ yield
20
+ end
21
+ end
22
+
23
+ end
24
+
25
+ def tags
26
+ []
27
+ end
28
+
29
+ private
30
+
31
+ def saved_data
32
+ raise NotImplemented
33
+ end
34
+
35
+ def load_data
36
+ raise NotImplemented
37
+ end
38
+
39
+ end
data/lib/sidekiq/haron/version.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Sidekiq
2
+ module Haron
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
data/sidekiq-haron.gemspec ADDED
@@ -0,0 +1,32 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "sidekiq/haron/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sidekiq-haron"
8
+ spec.version = Sidekiq::Haron::VERSION
9
+ spec.authors = ["Serg F"]
10
+ spec.email = ["wolferingys@gmail.com"]
11
+
12
+ spec.summary = %q{Transfer some data to sidekiq job and can tag sidekiq logs}
13
+ spec.description = %q{Transfer some data to sidekiq job and can tag sidekiq logs}
14
+ spec.homepage = "https://github.com/Rnd-Soft/sidekiq-haron"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
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", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ spec.add_development_dependency "awesome_print"
32
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq-haron
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Serg F
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sidekiq
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.17'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.17'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: awesome_print
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Transfer some data to sidekiq job and can tag sidekiq logs
98
+ email:
99
+ - wolferingys@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - lib/sidekiq/haron.rb
111
+ - lib/sidekiq/haron/client_middleware.rb
112
+ - lib/sidekiq/haron/exception_logger.rb
113
+ - lib/sidekiq/haron/formatter.rb
114
+ - lib/sidekiq/haron/job_logger.rb
115
+ - lib/sidekiq/haron/server_middleware.rb
116
+ - lib/sidekiq/haron/storage.rb
117
+ - lib/sidekiq/haron/transmitter.rb
118
+ - lib/sidekiq/haron/version.rb
119
+ - sidekiq-haron.gemspec
120
+ homepage: https://github.com/Rnd-Soft/sidekiq-haron
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubygems_version: 3.0.6
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Transfer some data to sidekiq job and can tag sidekiq logs
143
+ test_files: []