request_id 0.2.2 → 0.3.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
  SHA1:
3
- metadata.gz: 8856a6a5e319b628f1ed4250910bfd7d25dd8c05
4
- data.tar.gz: e0a27815a01b39ceca79ce73e66e97200a36cbfd
3
+ metadata.gz: a15cb25ed02ec17242c57798948853b77d0b097c
4
+ data.tar.gz: eed296879d558c00b33e507aa195482f29203dc8
5
5
  SHA512:
6
- metadata.gz: 6867acf52cf09b17c07b97d67d79823720a6120f972dbd253b5871fc0b223f04e54269eec093f072546910a3347a7602f6fb697393a3b836db7e7dcb8749b3f2
7
- data.tar.gz: 0564dd04447e5be593c7c73fd8a7e5c23458ed9104d419fa286eeec5dbda6fe29879939351d0941d91b416f9e670dfd220863cb5a523e9982478e0597a1aefab
6
+ metadata.gz: fe2d085fbe00596365443abcb878130ebcef0c7d367f3207e2e178ea32be493d3a339f217587fb3d08dd7eb9eabac7eade5ebc7d7261244743de58052202f610
7
+ data.tar.gz: 7f3543a463295b69d9767ac3b10b6f4a9573f843663a1ca68b0edf8276d21a8ac261871e328550747c81ec53f1565ee1536c6326e26e2a225744c8483e364d9d
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Remind101, Inc.
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.
@@ -1,3 +1,3 @@
1
1
  module RequestId
2
- VERSION = '0.2.2'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -2,31 +2,16 @@ module Sidekiq
2
2
  module Middleware
3
3
  module Client
4
4
  class RequestId
5
-
6
5
  def call(worker, item, queue)
7
6
  item['request_id'] = request_id if request_id
8
- log(request_id, worker, item['args'].inspect) if log_request_id?(worker)
9
7
  yield
10
8
  end
11
9
 
12
10
  private
13
11
 
14
- def log(request_id, worker, args)
15
- logger.info "request_id=#{request_id} at=enqueue worker=#{worker.to_s} args=#{args}"
16
- end
17
-
18
- def log_request_id?(worker)
19
- worker.respond_to?(:get_sidekiq_options) && worker.get_sidekiq_options['log_request_id']
20
- end
21
-
22
- def logger
23
- Sidekiq.logger
24
- end
25
-
26
12
  def request_id
27
13
  ::RequestId.request_id
28
14
  end
29
-
30
15
  end
31
16
  end
32
17
  end
@@ -13,22 +13,11 @@ module Sidekiq
13
13
  end
14
14
 
15
15
  def call(worker, item, queue)
16
- request_id = ::RequestId.request_id = item['request_id']
17
- Sidekiq::Logging.with_context("request_id=#{request_id} worker=#{worker.class.to_s} jid=#{item['jid']} args=#{item['args'].inspect}") do
18
- begin
19
- start = Time.now
20
- logger.info { "at=start" }
21
- yield
22
- logger.info { "at=done duration=#{elapsed(start)}sec" }
23
- rescue Exception
24
- logger.info { "at=fail duration=#{elapsed(start)}sec" }
25
- raise
26
- end
27
- end
16
+ ::RequestId.request_id = item['request_id']
17
+ yield
28
18
  ensure
29
19
  ::RequestId.request_id = nil unless self.class.no_reset
30
20
  end
31
-
32
21
  end
33
22
  end
34
23
  end
@@ -9,24 +9,11 @@ describe Sidekiq::Middleware::Client::RequestId do
9
9
  let(:worker) { double('worker', to_s: 'Worker') }
10
10
 
11
11
  context 'when the worker is configured to log request ids' do
12
- let(:logger) { double('Logger', info: nil) }
13
-
14
- before { worker.stub get_sidekiq_options: { 'log_request_id' => true } }
15
- before { Sidekiq.stub logger: logger }
16
-
17
12
  it 'adds the request id to the item' do
18
13
  request_id = Thread.current[:request_id] = SecureRandom.hex
19
14
  item = {}
20
15
  expect { middleware.call(worker, item, nil) { } }.to change { item }.from({}).to('request_id' => request_id)
21
16
  end
22
-
23
- it 'logs the request id' do
24
- request_id = Thread.current[:request_id] = SecureRandom.hex
25
- logger.should_receive(:info).with(
26
- "request_id=#{request_id} at=enqueue worker=Worker args=[\"foo\"]"
27
- )
28
- expect { |b| middleware.call(worker, { 'args' => ['foo'] }, nil, &b) }.to yield_control
29
- end
30
17
  end
31
18
 
32
19
  context 'when the worker is not configured to log request ids' do
@@ -2,11 +2,8 @@ require 'spec_helper'
2
2
  require 'securerandom'
3
3
 
4
4
  describe Sidekiq::Middleware::Server::RequestId do
5
- let(:logger) { double('Logger', info: nil) }
6
5
  let(:middleware) { described_class.new }
7
6
 
8
- before { Sidekiq.stub logger: logger }
9
-
10
7
  describe '#call' do
11
8
  let(:worker) { double('worker') }
12
9
 
@@ -15,20 +12,13 @@ describe Sidekiq::Middleware::Server::RequestId do
15
12
  context 'when the worker is configured to log request ids' do
16
13
  let(:request_id) { SecureRandom.hex }
17
14
  let(:job_id) { SecureRandom.hex }
18
- let(:item) { { 'jid' => job_id, 'args' => ['foo'], 'log_request_id' => true, 'request_id' => request_id } }
15
+ let(:item) { { 'jid' => job_id, 'args' => ['foo'], 'request_id' => request_id } }
19
16
 
20
17
  it 'sets a thread local to the request id' do
21
18
  Thread.current.should_receive(:[]=).with(:request_id, request_id)
22
19
  Thread.current.should_receive(:[]=).with(:request_id, nil)
23
20
  expect { |b| middleware.call(worker, item, nil, &b) }.to yield_control
24
21
  end
25
-
26
- it 'logs the request id' do
27
- Sidekiq::Logging.should_receive(:with_context)
28
- .with("request_id=#{request_id} worker=Worker jid=#{job_id} args=[\"foo\"]")
29
- .and_yield
30
- expect { |b| middleware.call(worker, item, nil, &b) }.to yield_control
31
- end
32
22
  end
33
23
 
34
24
  context 'when the worker is not configured to log request ids' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: request_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric J. Holmes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-08 00:00:00.000000000 Z
11
+ date: 2014-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -77,6 +77,7 @@ files:
77
77
  - .rspec
78
78
  - .travis.yml
79
79
  - Gemfile
80
+ - LICENSE
80
81
  - LICENSE.txt
81
82
  - README.md
82
83
  - Rakefile