-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from FundingCircle/USM-1820-add-support-for-s…
…idekiq-7 [USM-1820] Add support for Sidekiq 7
- Loading branch information
Showing
23 changed files
with
868 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.3.0" | ||
|
||
group :test do | ||
gem "simplecov", "~> 0.17.0" | ||
end | ||
|
||
gemspec path: "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.4.0" | ||
|
||
group :test do | ||
gem "simplecov", "~> 0.17.0" | ||
end | ||
|
||
gemspec path: "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.5.0" | ||
|
||
group :test do | ||
gem "simplecov", "~> 0.17.0" | ||
end | ||
|
||
gemspec path: "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", "~> 7.0.0" | ||
|
||
group :test do | ||
gem "simplecov", "~> 0.17.0" | ||
end | ||
|
||
gemspec path: "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", "~> 7.1.0" | ||
|
||
group :test do | ||
gem "simplecov", "~> 0.17.0" | ||
end | ||
|
||
gemspec path: "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
module Loga | ||
module Sidekiq | ||
def self.configure_logging | ||
return unless defined?(::Sidekiq) | ||
return if Gem::Version.new(::Sidekiq::VERSION) < Gem::Version.new('5.0') | ||
|
||
if Gem::Version.new(::Sidekiq::VERSION) < Gem::Version.new('6.0') | ||
require 'loga/sidekiq5/job_logger' | ||
|
||
::Sidekiq.configure_server do |config| | ||
config.options[:job_logger] = Loga::Sidekiq5::JobLogger | ||
end | ||
configure_for_sidekiq5 | ||
elsif Gem::Version.new(::Sidekiq::VERSION) < Gem::Version.new('7.0') | ||
require 'loga/sidekiq6/job_logger' | ||
configure_for_sidekiq6 | ||
elsif Gem::Version.new(::Sidekiq::VERSION) < Gem::Version.new('8.0') | ||
configure_for_sidekiq7 | ||
end | ||
end | ||
|
||
::Sidekiq.configure_server do |config| | ||
config.options[:job_logger] = Loga::Sidekiq6::JobLogger | ||
end | ||
def self.configure_for_sidekiq5 | ||
require 'loga/sidekiq5/job_logger' | ||
|
||
::Sidekiq.configure_server do |config| | ||
config.options[:job_logger] = Loga::Sidekiq5::JobLogger | ||
end | ||
|
||
::Sidekiq.logger = Loga.configuration.logger | ||
end | ||
|
||
def self.configure_for_sidekiq6 | ||
require 'loga/sidekiq6/job_logger' | ||
|
||
::Sidekiq.configure_server do |config| | ||
config.options[:job_logger] = Loga::Sidekiq6::JobLogger | ||
end | ||
|
||
::Sidekiq.logger = Loga.configuration.logger | ||
end | ||
|
||
def self.configure_for_sidekiq7 | ||
require 'loga/sidekiq7/job_logger' | ||
|
||
::Sidekiq.configure_server do |config| | ||
config[:job_logger] = Loga::Sidekiq7::JobLogger | ||
config.logger = Loga.configuration.logger | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'sidekiq/job_logger' | ||
|
||
module Loga | ||
module Sidekiq7 | ||
class JobLogger < ::Sidekiq::JobLogger | ||
EVENT_TYPE = 'sidekiq'.freeze | ||
|
||
def call(item, _queue) | ||
start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) | ||
|
||
yield | ||
|
||
::Sidekiq::Context.add(:elapsed, elapsed(start)) | ||
|
||
loga_log(message: "#{item['class']} with jid: '#{item['jid']}' done", item: item) | ||
rescue Exception => e # rubocop:disable Lint/RescueException | ||
::Sidekiq::Context.add(:elapsed, elapsed(start)) | ||
|
||
loga_log( | ||
message: "#{item['class']} with jid: '#{item['jid']}' fail", item: item, | ||
exception: e | ||
) | ||
|
||
raise | ||
end | ||
|
||
private | ||
|
||
def loga_log(message:, item:, exception: nil) | ||
data = item.select do |k, _v| | ||
%w[created_at enqueued_at jid queue retry | ||
class].include? k | ||
end | ||
|
||
data['params'] = item['args'] | ||
|
||
data['exception'] = exception if exception | ||
|
||
event = Event.new(type: EVENT_TYPE, message: message, data: data) | ||
|
||
if exception | ||
@logger.warn(event) | ||
else | ||
@logger.info(event) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Loga | ||
VERSION = '2.6.1'.freeze | ||
VERSION = '2.7.0'.freeze | ||
end |
Oops, something went wrong.