sidekiq_middlewares 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/.travis.yml +5 -5
- data/README.md +19 -6
- data/lib/sidekiq_middlewares.rb +2 -0
- data/lib/sidekiq_middlewares/benchmarker.rb +29 -27
- data/lib/sidekiq_middlewares/mdc_cleaner.rb +8 -0
- data/lib/sidekiq_middlewares/version.rb +1 -1
- data/sidekiq_middlewares.gemspec +12 -11
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ce493c5d4b804657ed9b78b09bc19c796f29991
|
4
|
+
data.tar.gz: f67f58242c92f348aed2517783634c06130fcde0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c672f9bf8978c7867d08f228011023383a7769f95014a1718210f64b6ce735618531d1fa9768fea6453b0fdedd31faac3e0a1c24ab0616e8055090ed2d1731e1
|
7
|
+
data.tar.gz: 12da02767215af852fe6c297c5d66f0701f6a08ad08cbcac8a34c3fcea78578a58aad40a720072f959a1d0b790a2a4da0bac9c5b4a2a53f2844d0e9d9cefafc8
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
language: ruby
|
2
|
-
script:
|
2
|
+
script: bundle exec rake
|
3
|
+
|
4
|
+
before_install:
|
5
|
+
- gem update --system --no-document
|
3
6
|
|
4
7
|
install:
|
5
8
|
- gem update bundler
|
6
9
|
- bundle install
|
7
10
|
|
8
11
|
rvm:
|
9
|
-
- 1.9
|
10
|
-
- 2.0.0
|
11
|
-
- 2.1.1
|
12
|
-
- 2.1.2
|
13
12
|
- 2.2.2
|
14
13
|
- 2.3.1
|
15
14
|
- 2.4.1
|
15
|
+
- 2.5.1
|
16
16
|
- jruby-19mode
|
17
17
|
|
18
18
|
- ruby-head
|
data/README.md
CHANGED
@@ -14,25 +14,38 @@ Ruby Sidekiq Middlewares For common uses
|
|
14
14
|
* this proc will receive one argument, a message object which is a Hash type
|
15
15
|
* If the logger can handle Hash messages, such as TwP's [logging](https://github.com/TwP/logging) libary, than you don't need this
|
16
16
|
|
17
|
-
|
18
|
-
require 'json'
|
19
|
-
require 'logger'
|
17
|
+
first you need a logger that respond to :info method, and format the message object into an expected format.
|
20
18
|
|
19
|
+
For simplicity, in the example this will be json.
|
20
|
+
```ruby
|
21
21
|
require 'json'
|
22
22
|
require 'logger'
|
23
|
-
|
24
23
|
json_logger = Logger.new(STDOUT)
|
25
24
|
json_logger.formatter = proc do |severity, datetime, progname, msg|
|
26
25
|
JSON.dump(msg) + "\n"
|
27
26
|
end
|
27
|
+
```
|
28
|
+
|
29
|
+
Than you can use it with the Benchmarker middleware like this:
|
28
30
|
|
31
|
+
```ruby
|
29
32
|
Sidekiq.configure_server do |config|
|
30
33
|
config.redis = sidekiq_redis_config
|
31
34
|
|
32
35
|
config.server_middleware do |chain|
|
33
36
|
chain.add SidekiqMiddlewares::Benchmarker, logger: json_logger
|
34
|
-
|
35
|
-
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
Or if you don't want to provide logger who also know about how to format, you can give an optional formatter to the middleware.
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
Sidekiq.configure_server do |config|
|
45
|
+
config.redis = sidekiq_redis_config
|
46
|
+
|
47
|
+
config.server_middleware do |chain|
|
48
|
+
chain.add SidekiqMiddlewares::Benchmarker, logger: Logger.new(STDOUT), formatter: proc { |m| JSON.dump(m) + "\n" }
|
36
49
|
end
|
37
50
|
end
|
38
51
|
```
|
data/lib/sidekiq_middlewares.rb
CHANGED
@@ -1,35 +1,37 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module SidekiqMiddlewares
|
2
|
+
class Benchmarker
|
3
3
|
|
4
|
-
|
4
|
+
def initialize(opts = {})
|
5
|
+
@logger = opts[:logger] || raise(ArgumentError, 'missing keyword: logger')
|
6
|
+
@formatter = opts[:formatter] || proc { |message| message }
|
7
|
+
end
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
def call(_worker, job, _queue)
|
10
|
+
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
11
|
+
yield
|
12
|
+
ensure
|
13
|
+
elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
|
14
|
+
@logger.info(@formatter.call(message_to_log(job, elapsed_time)))
|
15
|
+
end
|
10
16
|
|
11
|
-
|
12
|
-
measurement = Benchmark.measure(&next_middleware_call)
|
13
|
-
@logger.info(@formatter.call(message_to_log(job, measurement)))
|
14
|
-
end
|
17
|
+
private
|
15
18
|
|
16
|
-
|
19
|
+
def message_to_log(job, measurement)
|
20
|
+
base_by(job).merge(results_by(measurement))
|
21
|
+
end
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
'created_at' => job['created_at'],
|
28
|
-
'enqueued_at' => job['enqueued_at']
|
29
|
-
}
|
30
|
-
end
|
23
|
+
def base_by(job)
|
24
|
+
{
|
25
|
+
'jid' => job['jid'],
|
26
|
+
'queue' => job['queue'],
|
27
|
+
'worker_class' => job['class'],
|
28
|
+
'created_at' => job['created_at'],
|
29
|
+
'enqueued_at' => job['enqueued_at']
|
30
|
+
}
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
def results_by(elapsed_time)
|
34
|
+
{'execution_time_sec' => elapsed_time}
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
data/sidekiq_middlewares.gemspec
CHANGED
@@ -5,21 +5,22 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
require 'sidekiq_middlewares/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name
|
9
|
-
spec.version
|
10
|
-
spec.authors
|
11
|
-
spec.email
|
8
|
+
spec.name = 'sidekiq_middlewares'
|
9
|
+
spec.version = SidekiqMiddlewares::VERSION
|
10
|
+
spec.authors = ['Emarsys Smart Insight Team']
|
11
|
+
spec.email = ['smart-insight-dev@emarsys.com']
|
12
12
|
|
13
|
-
spec.summary
|
14
|
-
spec.description
|
15
|
-
spec.homepage
|
13
|
+
spec.summary = 'Commonly reused Sidekiq Middlewares such as Benchmarker'
|
14
|
+
spec.description = 'Commonly reused Sidekiq Middlewares such as Benchmarker'
|
15
|
+
spec.homepage = 'https://github.com/emartech/sidekiq_middlewares'
|
16
|
+
spec.required_ruby_version = ">= 2.2.2"
|
16
17
|
|
17
|
-
spec.files
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
19
|
f.match(%r{^(test|spec|features)/})
|
19
20
|
end
|
20
|
-
spec.bindir
|
21
|
-
spec.executables
|
22
|
-
spec.require_paths
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
23
24
|
|
24
25
|
spec.add_development_dependency 'bundler', '~> 1.14'
|
25
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq_middlewares
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emarsys Smart Insight Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- bin/setup
|
71
71
|
- lib/sidekiq_middlewares.rb
|
72
72
|
- lib/sidekiq_middlewares/benchmarker.rb
|
73
|
+
- lib/sidekiq_middlewares/mdc_cleaner.rb
|
73
74
|
- lib/sidekiq_middlewares/version.rb
|
74
75
|
- sidekiq_middlewares.gemspec
|
75
76
|
homepage: https://github.com/emartech/sidekiq_middlewares
|
@@ -83,7 +84,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
84
|
requirements:
|
84
85
|
- - ">="
|
85
86
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
87
|
+
version: 2.2.2
|
87
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
89
|
requirements:
|
89
90
|
- - ">="
|
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
92
|
version: '0'
|
92
93
|
requirements: []
|
93
94
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.6.13
|
95
96
|
signing_key:
|
96
97
|
specification_version: 4
|
97
98
|
summary: Commonly reused Sidekiq Middlewares such as Benchmarker
|