Skip to content

Commit ed96c3d

Browse files
authored
Merge pull request #127 from FundingCircle/fix-sidekiq-compatibility
Fix sidekiq6 compatibility
2 parents 73e7f29 + 6d41a80 commit ed96c3d

7 files changed

Lines changed: 39 additions & 13 deletions

File tree

Appraisals

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('2.5.0')
3434
appraise 'sidekiq6' do
3535
gem 'sidekiq', '~> 6.0'
3636
end
37+
38+
appraise 'sidekiq61' do
39+
gem 'sidekiq', '~> 6.1.0'
40+
end
3741
end
3842

3943
if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('2.7.0')

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [2.6.1] - 2022-02-22
8+
### Fixed
9+
- Fix compatibility with sidekiq 6.4.1
10+
711
## [2.6.0] - 2021-12-22
812
### Added
913
- Allow using the gem with rails 7

gemfiles/sidekiq61.gemfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "sidekiq", "~> 6.1.0"
6+
7+
group :test do
8+
gem "simplecov", "~> 0.17.0"
9+
end
10+
11+
gemspec path: "../"

lib/loga/sidekiq6/job_logger.rb

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,27 @@ def call(item, _queue)
1010

1111
yield
1212

13-
with_elapsed_time_context(start) do
14-
loga_log(
15-
message: "#{item['class']} with jid: '#{item['jid']}' done", item: item,
16-
)
17-
end
13+
::Sidekiq::Context.current[:elapsed] = elapsed(start)
14+
15+
loga_log(message: "#{item['class']} with jid: '#{item['jid']}' done", item: item)
1816
rescue Exception => e # rubocop:disable Lint/RescueException
19-
with_elapsed_time_context(start) do
20-
loga_log(
21-
message: "#{item['class']} with jid: '#{item['jid']}' fail", item: item,
22-
exception: e
23-
)
24-
end
17+
::Sidekiq::Context.current[:elapsed] = elapsed(start)
18+
19+
loga_log(
20+
message: "#{item['class']} with jid: '#{item['jid']}' fail", item: item,
21+
exception: e
22+
)
2523

2624
raise
2725
end
2826

27+
def prepare(job_hash, &block)
28+
super
29+
ensure
30+
# For sidekiq version < 6.4
31+
Thread.current[:sidekiq_context] = nil
32+
end
33+
2934
private
3035

3136
def loga_log(message:, item:, exception: nil)

lib/loga/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Loga
2-
VERSION = '2.6.0'.freeze
2+
VERSION = '2.6.1'.freeze
33
end

spec/loga/sidekiq6/job_logger_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464

6565
aggregate_failures do
6666
expect(json_line).to include(expected_body)
67+
expect(json_line['_duration']).to be_a(Float)
6768
expect(json_line['timestamp']).to be_a(Float)
6869
expect(json_line['host']).to be_a(String)
6970
expect(json_line['short_message']).to match(/HardWorker with jid:*/)
@@ -110,6 +111,7 @@
110111

111112
aggregate_failures do
112113
expect(&failed_job).to raise_error(StandardError)
114+
expect(json_line['_duration']).to be_a(Float)
113115
expect(json_line).to include(expected_body)
114116
expect(json_line['timestamp']).to be_a(Float)
115117
expect(json_line['host']).to be_a(String)

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
'spec/loga/sidekiq5/**/*_spec.rb',
3838
'spec/loga/sidekiq_spec.rb',
3939
].join(',')
40-
when '6'
40+
when '6', '61'
4141
rspec_pattern = [
4242
'spec/integration/sidekiq6_spec.rb',
4343
'spec/loga/sidekiq6/**/*_spec.rb',

0 commit comments

Comments
 (0)