Skip to content

Commit

Permalink
Merge pull request #127 from FundingCircle/fix-sidekiq-compatibility
Browse files Browse the repository at this point in the history
Fix sidekiq6 compatibility
  • Loading branch information
bliof-fc committed Feb 22, 2022
2 parents 73e7f29 + 6d41a80 commit ed96c3d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 13 deletions.
4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('2.5.0')
appraise 'sidekiq6' do
gem 'sidekiq', '~> 6.0'
end

appraise 'sidekiq61' do
gem 'sidekiq', '~> 6.1.0'
end
end

if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('2.7.0')
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.6.1] - 2022-02-22
### Fixed
- Fix compatibility with sidekiq 6.4.1

## [2.6.0] - 2021-12-22
### Added
- Allow using the gem with rails 7
Expand Down
11 changes: 11 additions & 0 deletions gemfiles/sidekiq61.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "sidekiq", "~> 6.1.0"

group :test do
gem "simplecov", "~> 0.17.0"
end

gemspec path: "../"
27 changes: 16 additions & 11 deletions lib/loga/sidekiq6/job_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,27 @@ def call(item, _queue)

yield

with_elapsed_time_context(start) do
loga_log(
message: "#{item['class']} with jid: '#{item['jid']}' done", item: item,
)
end
::Sidekiq::Context.current[:elapsed] = elapsed(start)

loga_log(message: "#{item['class']} with jid: '#{item['jid']}' done", item: item)
rescue Exception => e # rubocop:disable Lint/RescueException
with_elapsed_time_context(start) do
loga_log(
message: "#{item['class']} with jid: '#{item['jid']}' fail", item: item,
exception: e
)
end
::Sidekiq::Context.current[:elapsed] = elapsed(start)

loga_log(
message: "#{item['class']} with jid: '#{item['jid']}' fail", item: item,
exception: e
)

raise
end

def prepare(job_hash, &block)
super
ensure
# For sidekiq version < 6.4
Thread.current[:sidekiq_context] = nil
end

private

def loga_log(message:, item:, exception: nil)
Expand Down
2 changes: 1 addition & 1 deletion lib/loga/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Loga
VERSION = '2.6.0'.freeze
VERSION = '2.6.1'.freeze
end
2 changes: 2 additions & 0 deletions spec/loga/sidekiq6/job_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

aggregate_failures do
expect(json_line).to include(expected_body)
expect(json_line['_duration']).to be_a(Float)
expect(json_line['timestamp']).to be_a(Float)
expect(json_line['host']).to be_a(String)
expect(json_line['short_message']).to match(/HardWorker with jid:*/)
Expand Down Expand Up @@ -110,6 +111,7 @@

aggregate_failures do
expect(&failed_job).to raise_error(StandardError)
expect(json_line['_duration']).to be_a(Float)
expect(json_line).to include(expected_body)
expect(json_line['timestamp']).to be_a(Float)
expect(json_line['host']).to be_a(String)
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
'spec/loga/sidekiq5/**/*_spec.rb',
'spec/loga/sidekiq_spec.rb',
].join(',')
when '6'
when '6', '61'
rspec_pattern = [
'spec/integration/sidekiq6_spec.rb',
'spec/loga/sidekiq6/**/*_spec.rb',
Expand Down

0 comments on commit ed96c3d

Please sign in to comment.