From 3f61386ee824b5c605d22342dac341721fe6d135 Mon Sep 17 00:00:00 2001 From: Robert Gradowski Date: Wed, 9 Oct 2024 18:54:25 +0200 Subject: [PATCH 01/14] remedy logic, gemfile, gemspec, CI --- .github/workflows/ci.yml | 37 ++++++++++ Gemfile | 7 +- Gemfile.lock | 87 +++++++++++++++++++++++ README.md | 6 +- lib/remedy/version.rb | 7 ++ lib/sidekiq/poison/pill/remedy.rb | 14 ---- lib/sidekiq/poison/pill/remedy/version.rb | 11 --- lib/sidekiq_poison_pill_remedy.rb | 41 +++++++++++ sidekiq-poison-pill-remedy.gemspec | 16 ++--- spec/sidekiq/poison/pill/remedy_spec.rb | 11 --- spec/sidekiq_poison_pill_remedy_spec.rb | 13 ++++ spec/spec_helper.rb | 4 +- 12 files changed, 203 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 Gemfile.lock create mode 100644 lib/remedy/version.rb delete mode 100644 lib/sidekiq/poison/pill/remedy.rb delete mode 100644 lib/sidekiq/poison/pill/remedy/version.rb create mode 100644 lib/sidekiq_poison_pill_remedy.rb delete mode 100644 spec/sidekiq/poison/pill/remedy_spec.rb create mode 100644 spec/sidekiq_poison_pill_remedy_spec.rb diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ea773bd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: CI +on: [pull_request, push] +jobs: + rubocop: + strategy: + fail-fast: true + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.1 + bundler-cache: true + - run: bundle exec rubocop + rspec: + strategy: + fail-fast: false + matrix: + ruby: ['3.1', '3.2', '3.3'] + runs-on: ubuntu-latest + services: + redis: + image: redis + ports: + - 6379:6379 + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - run: bundle exec rake \ No newline at end of file diff --git a/Gemfile b/Gemfile index 03278df..52bca7f 100644 --- a/Gemfile +++ b/Gemfile @@ -6,5 +6,10 @@ source "https://rubygems.org" gemspec gem "rake", "~> 13.0" - gem "rspec", "~> 3.0" +gem 'rubocop', '~> 1.40', require: false +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem 'sidekiq' +gem 'sentry-ruby' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..101d0fb --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,87 @@ +PATH + remote: . + specs: + sidekiq-poison-pill-remedy (0.1.0) + +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.2) + bigdecimal (3.1.8) + concurrent-ruby (1.3.4) + connection_pool (2.4.1) + diff-lcs (1.5.1) + json (2.7.2) + language_server-protocol (3.17.0.3) + logger (1.6.1) + parallel (1.26.3) + parser (3.3.5.0) + ast (~> 2.4.1) + racc + racc (1.8.1) + rack (3.1.7) + rainbow (3.1.1) + rake (13.2.1) + redis-client (0.22.2) + connection_pool + regexp_parser (2.9.2) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.1) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) + rubocop (1.66.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.4, < 3.0) + rubocop-ast (>= 1.32.2, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.32.3) + parser (>= 3.3.1.0) + rubocop-performance (1.22.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (3.1.0) + rubocop (~> 1.61) + ruby-progressbar (1.13.0) + sentry-ruby (5.21.0) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + sidekiq (7.3.2) + concurrent-ruby (< 2) + connection_pool (>= 2.3.0) + logger + rack (>= 2.2.4) + redis-client (>= 0.22.2) + unicode-display_width (2.6.0) + +PLATFORMS + arm64-darwin-22 + +DEPENDENCIES + rake (~> 13.0) + rspec (~> 3.0) + rubocop (~> 1.40) + rubocop-performance + rubocop-rake + rubocop-rspec + sentry-ruby + sidekiq + sidekiq-poison-pill-remedy! + +BUNDLED WITH + 2.4.18 diff --git a/README.md b/README.md index cf430d3..0487ad8 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ -# Sidekiq::Poison::Pill::Remedy +# SidekiqPoisonPillRemedy -TODO: Delete this and the text below, and describe your gem - -Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sidekiq/poison/pill/remedy`. To experiment with that code, run `bin/console` for an interactive prompt. +The Sidekiq Poison Pill Remedy gem enhances Sidekiq's job processing by automatically handling and rescheduling failed jobs (poison pills) with integrated logging and error tracking through Sentry, ultimately improving reliability and performance optimization. ## Installation diff --git a/lib/remedy/version.rb b/lib/remedy/version.rb new file mode 100644 index 0000000..214cd96 --- /dev/null +++ b/lib/remedy/version.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module SidekiqPoisonPillRemedy + module Version + end + VERSION = '0.1.0' +end diff --git a/lib/sidekiq/poison/pill/remedy.rb b/lib/sidekiq/poison/pill/remedy.rb deleted file mode 100644 index 238011c..0000000 --- a/lib/sidekiq/poison/pill/remedy.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -require_relative "remedy/version" - -module Sidekiq - module Poison - module Pill - module Remedy - class Error < StandardError; end - # Your code goes here... - end - end - end -end diff --git a/lib/sidekiq/poison/pill/remedy/version.rb b/lib/sidekiq/poison/pill/remedy/version.rb deleted file mode 100644 index 075ca78..0000000 --- a/lib/sidekiq/poison/pill/remedy/version.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -module Sidekiq - module Poison - module Pill - module Remedy - VERSION = "0.1.0" - end - end - end -end diff --git a/lib/sidekiq_poison_pill_remedy.rb b/lib/sidekiq_poison_pill_remedy.rb new file mode 100644 index 0000000..ef1c77c --- /dev/null +++ b/lib/sidekiq_poison_pill_remedy.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require_relative "../lib/remedy/version" + +module SidekiqPoisonPillRemedy + def self.remedy + Proc.new do |_jobstr, pill| + next unless pill + + job = Sidekiq::DeadSet.new.find_job(pill.jid) + + if job.queue == "poison_pill" + capture_sentry_message( + "#{job.klass} failed in the `#{job.queue}`, this means that it has to be urgently optimized on memory usage", + level: :critical, + job_item: job.item + ) + else + capture_sentry_message( + "#{job.klass} was marked as `poison pill`, please create the job memory optimizations ticket timely", + level: :warning, + job_item: job.item + ) + job.klass.constantize.set(queue: :poison_pill).perform_async(*job.args) + job.delete + end + end + end + + def self.capture_sentry_message(message, level:, job_item:) + if defined?(Sentry) + Sentry.capture_message( + message, + level: level, + extra: { job_item: job_item } + ) + end + + Sidekiq.logger.fatal(message) + end +end diff --git a/sidekiq-poison-pill-remedy.gemspec b/sidekiq-poison-pill-remedy.gemspec index 10c8182..993052a 100644 --- a/sidekiq-poison-pill-remedy.gemspec +++ b/sidekiq-poison-pill-remedy.gemspec @@ -1,24 +1,24 @@ # frozen_string_literal: true -require_relative "lib/sidekiq/poison/pill/remedy/version" +require_relative "lib/remedy/version" Gem::Specification.new do |spec| spec.name = "sidekiq-poison-pill-remedy" - spec.version = Sidekiq::Poison::Pill::Remedy::VERSION + spec.version = SidekiqPoisonPillRemedy::VERSION spec.authors = ["Karol Galanciak"] spec.email = ["karol.galanciak@gmail.com"] - spec.summary = "TODO: Write a short summary, because RubyGems requires one." - spec.description = "TODO: Write a longer description or delete this line." - spec.homepage = "TODO: Put your gem's website or public repo URL here." + spec.summary = "Enhances Sidekiq's job processing by automatically handling and rescheduling failed jobs (poison pills)" + spec.description = "Enhances Sidekiq's job processing by automatically handling and rescheduling failed jobs (poison pills)" + spec.homepage = "https://example.com" spec.license = "MIT" spec.required_ruby_version = ">= 3.0.0" - spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'" + # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'" spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here." - spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here." + spec.metadata["source_code_uri"] = "https://example.com" + spec.metadata["changelog_uri"] = "https://example.com" # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. diff --git a/spec/sidekiq/poison/pill/remedy_spec.rb b/spec/sidekiq/poison/pill/remedy_spec.rb deleted file mode 100644 index d159a00..0000000 --- a/spec/sidekiq/poison/pill/remedy_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe Sidekiq::Poison::Pill::Remedy do - it "has a version number" do - expect(Sidekiq::Poison::Pill::Remedy::VERSION).not_to be nil - end - - it "does something useful" do - expect(false).to eq(true) - end -end diff --git a/spec/sidekiq_poison_pill_remedy_spec.rb b/spec/sidekiq_poison_pill_remedy_spec.rb new file mode 100644 index 0000000..3806335 --- /dev/null +++ b/spec/sidekiq_poison_pill_remedy_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require_relative '../lib/sidekiq_poison_pill_remedy' + +RSpec.describe SidekiqPoisonPillRemedy do + it 'has a version number' do + expect(SidekiqPoisonPillRemedy::VERSION).not_to be nil + end + + it 'does something useful' do + expect(false).to eq(true) + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 901a1e8..0b94aab 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require "sidekiq/poison/pill/remedy" +require_relative '../lib/sidekiq_poison_pill_remedy' RSpec.configure do |config| # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = ".rspec_status" + config.example_status_persistence_file_path = '.rspec_status' # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! From d0bc6edbbebbabaacbd94590701096b10657851a Mon Sep 17 00:00:00 2001 From: Robert Gradowski Date: Wed, 9 Oct 2024 19:00:54 +0200 Subject: [PATCH 02/14] add-platform x86_64-linux --- Gemfile.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile.lock b/Gemfile.lock index 101d0fb..8b56d49 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -71,6 +71,7 @@ GEM PLATFORMS arm64-darwin-22 + x86_64-linux DEPENDENCIES rake (~> 13.0) From 014f1b060fb44645963925de5ca60e63e16e06f7 Mon Sep 17 00:00:00 2001 From: Robert Gradowski Date: Thu, 10 Oct 2024 17:38:32 +0200 Subject: [PATCH 03/14] changes according to review, rubocop, readme --- .gitignore | 2 ++ .rubocop.yml | 8 +++++++ Gemfile | 13 +++++----- Gemfile.lock | 25 +++++++++---------- README.md | 18 ++++++++------ Rakefile | 4 ++-- bin/console | 6 ++--- lib/sidekiq_poison_pill_remedy.rb | 6 ++--- sidekiq-poison-pill-remedy.gemspec | 32 ++++++++++++------------- spec/sidekiq_poison_pill_remedy_spec.rb | 2 +- spec/spec_helper.rb | 2 -- 11 files changed, 64 insertions(+), 54 deletions(-) create mode 100644 .rubocop.yml diff --git a/.gitignore b/.gitignore index b04a8c8..541570a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ # rspec failure tracking .rspec_status + +Gemfile.lock \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..e0968f9 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,8 @@ +Style/Documentation: + Enabled: false +AllCops: + NewCops: enable +Metrics/AbcSize: + Max: 19 +Metrics/MethodLength: + Max: 20 # Increase the limit diff --git a/Gemfile b/Gemfile index 52bca7f..7d28ee2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,15 +1,14 @@ # frozen_string_literal: true -source "https://rubygems.org" +source 'https://rubygems.org' # Specify your gem's dependencies in sidekiq-poison-pill-remedy.gemspec gemspec -gem "rake", "~> 13.0" -gem "rspec", "~> 3.0" +gem 'rake', '~> 13.0' +gem 'rspec', '~> 3.0' gem 'rubocop', '~> 1.40', require: false -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" -gem 'sidekiq' +gem 'rubocop-performance' +gem 'rubocop-rake' +gem 'rubocop-rspec' gem 'sentry-ruby' diff --git a/Gemfile.lock b/Gemfile.lock index 8b56d49..50acf99 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,6 +2,7 @@ PATH remote: . specs: sidekiq-poison-pill-remedy (0.1.0) + true GEM remote: https://rubygems.org/ @@ -9,21 +10,21 @@ GEM ast (2.4.2) bigdecimal (3.1.8) concurrent-ruby (1.3.4) - connection_pool (2.4.1) diff-lcs (1.5.1) + ffi (1.17.0-arm64-darwin) + ffi (1.17.0-x86_64-linux-gnu) json (2.7.2) language_server-protocol (3.17.0.3) - logger (1.6.1) parallel (1.26.3) parser (3.3.5.0) ast (~> 2.4.1) racc racc (1.8.1) - rack (3.1.7) rainbow (3.1.1) rake (13.2.1) - redis-client (0.22.2) - connection_pool + rb-fsevent (0.11.2) + rb-inotify (0.11.1) + ffi (~> 1.0) regexp_parser (2.9.2) rspec (3.13.0) rspec-core (~> 3.13.0) @@ -58,15 +59,16 @@ GEM rubocop-rspec (3.1.0) rubocop (~> 1.61) ruby-progressbar (1.13.0) + sass (3.7.4) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) sentry-ruby (5.21.0) bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) - sidekiq (7.3.2) - concurrent-ruby (< 2) - connection_pool (>= 2.3.0) - logger - rack (>= 2.2.4) - redis-client (>= 0.22.2) + true (2.2.2) + sass (~> 3.4) unicode-display_width (2.6.0) PLATFORMS @@ -81,7 +83,6 @@ DEPENDENCIES rubocop-rake rubocop-rspec sentry-ruby - sidekiq sidekiq-poison-pill-remedy! BUNDLED WITH diff --git a/README.md b/README.md index 0487ad8..fb45eab 100644 --- a/README.md +++ b/README.md @@ -4,19 +4,23 @@ The Sidekiq Poison Pill Remedy gem enhances Sidekiq's job processing by automati ## Installation -TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org. +Add this line to your application's Gemfile: -Install the gem and add to the application's Gemfile by executing: +`gem 'sidekiq-poison-pill-remedy'` - $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG +And then execute: -If bundler is not being used to manage dependencies, install the gem by executing: +`$ bundle install` - $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG +Or install it yourself as: + +`$ gem install sidekiq-poison-pill-remedy` ## Usage -TODO: Write usage instructions here +The gem is supposed to be used in the following way when added to the application + +`config.super_fetch!(&SidekiqPoisonPillRemedy.remedy)` ## Development @@ -26,7 +30,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sidekiq-poison-pill-remedy. +Bug reports and pull requests are welcome on GitHub at https://github.com/BookingSync/sidekiq-poison-pill-remedy. ## License diff --git a/Rakefile b/Rakefile index b6ae734..82bb534 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ # frozen_string_literal: true -require "bundler/gem_tasks" -require "rspec/core/rake_task" +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) diff --git a/bin/console b/bin/console index 72d021f..f836a9f 100755 --- a/bin/console +++ b/bin/console @@ -1,11 +1,11 @@ #!/usr/bin/env ruby # frozen_string_literal: true -require "bundler/setup" -require "sidekiq/poison/pill/remedy" +require 'bundler/setup' +require 'sidekiq/poison/pill/remedy' # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. -require "irb" +require 'irb' IRB.start(__FILE__) diff --git a/lib/sidekiq_poison_pill_remedy.rb b/lib/sidekiq_poison_pill_remedy.rb index ef1c77c..60e2331 100644 --- a/lib/sidekiq_poison_pill_remedy.rb +++ b/lib/sidekiq_poison_pill_remedy.rb @@ -1,15 +1,13 @@ # frozen_string_literal: true -require_relative "../lib/remedy/version" - module SidekiqPoisonPillRemedy def self.remedy - Proc.new do |_jobstr, pill| + proc do |_jobstr, pill| next unless pill job = Sidekiq::DeadSet.new.find_job(pill.jid) - if job.queue == "poison_pill" + if job.queue == 'poison_pill' capture_sentry_message( "#{job.klass} failed in the `#{job.queue}`, this means that it has to be urgently optimized on memory usage", level: :critical, diff --git a/sidekiq-poison-pill-remedy.gemspec b/sidekiq-poison-pill-remedy.gemspec index 993052a..3928eae 100644 --- a/sidekiq-poison-pill-remedy.gemspec +++ b/sidekiq-poison-pill-remedy.gemspec @@ -1,24 +1,22 @@ # frozen_string_literal: true -require_relative "lib/remedy/version" +require_relative 'lib/remedy/version' Gem::Specification.new do |spec| - spec.name = "sidekiq-poison-pill-remedy" + spec.name = 'sidekiq-poison-pill-remedy' spec.version = SidekiqPoisonPillRemedy::VERSION - spec.authors = ["Karol Galanciak"] - spec.email = ["karol.galanciak@gmail.com"] + spec.authors = ['Karol Galanciak'] + spec.email = ['karol.galanciak@gmail.com'] - spec.summary = "Enhances Sidekiq's job processing by automatically handling and rescheduling failed jobs (poison pills)" - spec.description = "Enhances Sidekiq's job processing by automatically handling and rescheduling failed jobs (poison pills)" - spec.homepage = "https://example.com" - spec.license = "MIT" - spec.required_ruby_version = ">= 3.0.0" + spec.summary = "Enhances Sidekiq's job processing by automatically handling and rescheduling poison pills" + spec.description = "Enhances Sidekiq's job processing by automatically handling and rescheduling poison pills" + spec.homepage = 'https://github.com/BookingSync/sidekiq-poison-pill-remedy' + spec.license = 'MIT' + spec.required_ruby_version = '>= 3.0.0' - # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'" - - spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "https://example.com" - spec.metadata["changelog_uri"] = "https://example.com" + spec.metadata['homepage_uri'] = spec.homepage + spec.metadata['source_code_uri'] = 'https://github.com/BookingSync/sidekiq-poison-pill-remedy' + spec.metadata['changelog_uri'] = 'https://github.com/BookingSync/sidekiq-poison-pill-remedy/blob/master/CHANGELOG.md' # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. @@ -29,13 +27,15 @@ Gem::Specification.new do |spec| f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile]) end end - spec.bindir = "exe" + spec.bindir = 'exe' spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] + spec.require_paths = ['lib'] # Uncomment to register a new dependency of your gem # spec.add_dependency "example-gem", "~> 1.0" + spec.add_dependency gem 'sidekiq' # For more information and examples about making a new gem, check out our # guide at: https://bundler.io/guides/creating_gem.html + spec.metadata['rubygems_mfa_required'] = 'true' end diff --git a/spec/sidekiq_poison_pill_remedy_spec.rb b/spec/sidekiq_poison_pill_remedy_spec.rb index 3806335..cd099c2 100644 --- a/spec/sidekiq_poison_pill_remedy_spec.rb +++ b/spec/sidekiq_poison_pill_remedy_spec.rb @@ -8,6 +8,6 @@ end it 'does something useful' do - expect(false).to eq(true) + expect(true).to eq(true) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0b94aab..7ee4005 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative '../lib/sidekiq_poison_pill_remedy' - RSpec.configure do |config| # Enable flags like --only-failures and --next-failure config.example_status_persistence_file_path = '.rspec_status' From ed404b5859fb65e48192e40b208a843cda3c70f5 Mon Sep 17 00:00:00 2001 From: Robert Gradowski Date: Thu, 10 Oct 2024 17:42:28 +0200 Subject: [PATCH 04/14] gemspec edit --- Gemfile.lock | 25 ++++++++++++------------- sidekiq-poison-pill-remedy.gemspec | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 50acf99..0da6042 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ PATH remote: . specs: sidekiq-poison-pill-remedy (0.1.0) - true + sidekiq GEM remote: https://rubygems.org/ @@ -10,21 +10,21 @@ GEM ast (2.4.2) bigdecimal (3.1.8) concurrent-ruby (1.3.4) + connection_pool (2.4.1) diff-lcs (1.5.1) - ffi (1.17.0-arm64-darwin) - ffi (1.17.0-x86_64-linux-gnu) json (2.7.2) language_server-protocol (3.17.0.3) + logger (1.6.1) parallel (1.26.3) parser (3.3.5.0) ast (~> 2.4.1) racc racc (1.8.1) + rack (3.1.7) rainbow (3.1.1) rake (13.2.1) - rb-fsevent (0.11.2) - rb-inotify (0.11.1) - ffi (~> 1.0) + redis-client (0.22.2) + connection_pool regexp_parser (2.9.2) rspec (3.13.0) rspec-core (~> 3.13.0) @@ -59,16 +59,15 @@ GEM rubocop-rspec (3.1.0) rubocop (~> 1.61) ruby-progressbar (1.13.0) - sass (3.7.4) - sass-listen (~> 4.0.0) - sass-listen (4.0.0) - rb-fsevent (~> 0.9, >= 0.9.4) - rb-inotify (~> 0.9, >= 0.9.7) sentry-ruby (5.21.0) bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) - true (2.2.2) - sass (~> 3.4) + sidekiq (7.3.2) + concurrent-ruby (< 2) + connection_pool (>= 2.3.0) + logger + rack (>= 2.2.4) + redis-client (>= 0.22.2) unicode-display_width (2.6.0) PLATFORMS diff --git a/sidekiq-poison-pill-remedy.gemspec b/sidekiq-poison-pill-remedy.gemspec index 3928eae..c54a661 100644 --- a/sidekiq-poison-pill-remedy.gemspec +++ b/sidekiq-poison-pill-remedy.gemspec @@ -33,7 +33,7 @@ Gem::Specification.new do |spec| # Uncomment to register a new dependency of your gem # spec.add_dependency "example-gem", "~> 1.0" - spec.add_dependency gem 'sidekiq' + spec.add_dependency 'sidekiq' # For more information and examples about making a new gem, check out our # guide at: https://bundler.io/guides/creating_gem.html From 8b20c9e0baa56566eb6735774a1ca02495e130dd Mon Sep 17 00:00:00 2001 From: Robert Gradowski Date: Wed, 23 Oct 2024 17:20:38 +0200 Subject: [PATCH 05/14] spec edit --- .rubocop.yml | 2 +- Gemfile.lock | 6 +++++ lib/sidekiq-poison-pill-remedy.rb | 3 +++ lib/{remedy => }/version.rb | 0 sidekiq-poison-pill-remedy.gemspec | 3 ++- spec/sidekiq_poison_pill_remedy_spec.rb | 31 +++++++++++++++++++++---- spec/spec_helper.rb | 13 +++++++++++ spec/support/my_job.rb | 7 ++++++ 8 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 lib/sidekiq-poison-pill-remedy.rb rename lib/{remedy => }/version.rb (100%) create mode 100644 spec/support/my_job.rb diff --git a/.rubocop.yml b/.rubocop.yml index e0968f9..2b9e324 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,4 +5,4 @@ AllCops: Metrics/AbcSize: Max: 19 Metrics/MethodLength: - Max: 20 # Increase the limit + Max: 20 \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 0da6042..abcb94b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,6 +38,11 @@ GEM rspec-mocks (3.13.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) + rspec-sidekiq (5.0.0) + rspec-core (~> 3.0) + rspec-expectations (~> 3.0) + rspec-mocks (~> 3.0) + sidekiq (>= 5, < 8) rspec-support (3.13.1) rubocop (1.66.1) json (~> 2.3) @@ -77,6 +82,7 @@ PLATFORMS DEPENDENCIES rake (~> 13.0) rspec (~> 3.0) + rspec-sidekiq rubocop (~> 1.40) rubocop-performance rubocop-rake diff --git a/lib/sidekiq-poison-pill-remedy.rb b/lib/sidekiq-poison-pill-remedy.rb new file mode 100644 index 0000000..78c0ba0 --- /dev/null +++ b/lib/sidekiq-poison-pill-remedy.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +require 'sidekiq_poison_pill_remedy' diff --git a/lib/remedy/version.rb b/lib/version.rb similarity index 100% rename from lib/remedy/version.rb rename to lib/version.rb diff --git a/sidekiq-poison-pill-remedy.gemspec b/sidekiq-poison-pill-remedy.gemspec index c54a661..577a744 100644 --- a/sidekiq-poison-pill-remedy.gemspec +++ b/sidekiq-poison-pill-remedy.gemspec @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'lib/remedy/version' +require_relative 'lib/version' Gem::Specification.new do |spec| spec.name = 'sidekiq-poison-pill-remedy' @@ -34,6 +34,7 @@ Gem::Specification.new do |spec| # Uncomment to register a new dependency of your gem # spec.add_dependency "example-gem", "~> 1.0" spec.add_dependency 'sidekiq' + spec.add_development_dependency 'rspec-sidekiq' # For more information and examples about making a new gem, check out our # guide at: https://bundler.io/guides/creating_gem.html diff --git a/spec/sidekiq_poison_pill_remedy_spec.rb b/spec/sidekiq_poison_pill_remedy_spec.rb index cd099c2..63a78cf 100644 --- a/spec/sidekiq_poison_pill_remedy_spec.rb +++ b/spec/sidekiq_poison_pill_remedy_spec.rb @@ -1,13 +1,34 @@ # frozen_string_literal: true -require_relative '../lib/sidekiq_poison_pill_remedy' +require 'sidekiq/testing' +require 'rspec-sidekiq' +require 'sidekiq' +require 'sidekiq-poison-pill-remedy' +require 'support/my_job' RSpec.describe SidekiqPoisonPillRemedy do - it 'has a version number' do - expect(SidekiqPoisonPillRemedy::VERSION).not_to be nil + let(:job_args) { ['test_argument'] } + let(:jid) { MyJob.perform_async(*job_args) } + + before do + Sidekiq::Testing.fake! end - it 'does something useful' do - expect(true).to eq(true) + it 'moves job to poison_pill queue and logs message' do + begin + MyJob.new.perform('fail') + rescue StandardError + nil + end + + job = Sidekiq::DeadSet.new.find_job(jid) + + expect(job).not_to be_nil + expect(job.klass).to eq('MyJob') + + SidekiqPoisonPillRemedy.remedy.call(nil, job) + + poison_pill_job = Sidekiq::Queue.new('poison_pill').find_job(job.jid) + expect(poison_pill_job).not_to be_nil end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7ee4005..5b8cf22 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,12 @@ # frozen_string_literal: true +require 'bundler/setup' +require 'sidekiq/testing' +require 'rspec-sidekiq' +require 'sentry-ruby' +require 'sidekiq' +require 'sidekiq-poison-pill-remedy' + RSpec.configure do |config| # Enable flags like --only-failures and --next-failure config.example_status_persistence_file_path = '.rspec_status' @@ -10,4 +17,10 @@ config.expect_with :rspec do |c| c.syntax = :expect end + + config.before(:all) do + ENV['REDIS_URL'] ||= 'redis://localhost:6379/1' + end + + Dir[File.join(__dir__, 'support', '**', '*.rb')].each { |f| require f } end diff --git a/spec/support/my_job.rb b/spec/support/my_job.rb new file mode 100644 index 0000000..d2cf526 --- /dev/null +++ b/spec/support/my_job.rb @@ -0,0 +1,7 @@ +class MyJob + include Sidekiq::Worker + + def perform(arg) + raise 'An error occurred!' if arg == 'fail' + end +end From 2d4e506900ac5e888bb3bb42e38e1eb572c1cb96 Mon Sep 17 00:00:00 2001 From: Robert Gradowski Date: Wed, 23 Oct 2024 23:10:50 +0200 Subject: [PATCH 06/14] changes in spec --- spec/sidekiq_poison_pill_remedy_spec.rb | 26 ++++++++++++++++--------- spec/spec_helper.rb | 5 +++-- spec/support/my_job.rb | 10 ++++++++-- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/spec/sidekiq_poison_pill_remedy_spec.rb b/spec/sidekiq_poison_pill_remedy_spec.rb index 63a78cf..20cbef6 100644 --- a/spec/sidekiq_poison_pill_remedy_spec.rb +++ b/spec/sidekiq_poison_pill_remedy_spec.rb @@ -5,30 +5,38 @@ require 'sidekiq' require 'sidekiq-poison-pill-remedy' require 'support/my_job' +require 'sidekiq/api' RSpec.describe SidekiqPoisonPillRemedy do - let(:job_args) { ['test_argument'] } - let(:jid) { MyJob.perform_async(*job_args) } - before do Sidekiq::Testing.fake! end - it 'moves job to poison_pill queue and logs message' do - begin - MyJob.new.perform('fail') - rescue StandardError - nil - end + puts '1' + jid = MyJob.perform_async('fail') + puts "Jobs in Queue: #{Sidekiq::Queue.new.size}" + puts "DeadSet size: #{Sidekiq::DeadSet.new.size}" + puts '2' + + MyJob.drain + puts '3' job = Sidekiq::DeadSet.new.find_job(jid) + puts '4' + puts "Job JID: #{jid}" + puts "DeadSet size: #{Sidekiq::DeadSet.new.size}" expect(job).not_to be_nil expect(job.klass).to eq('MyJob') SidekiqPoisonPillRemedy.remedy.call(nil, job) + puts "DeadSet jobs: #{Sidekiq::DeadSet.new.size}" + puts "Queue jobs: #{Sidekiq::Queue.new.size}" + puts "Job JID: #{jid}" + poison_pill_job = Sidekiq::Queue.new('poison_pill').find_job(job.jid) expect(poison_pill_job).not_to be_nil + puts "Poison Pill Job JID: #{poison_pill_job.jid}" end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5b8cf22..439897b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,7 +7,10 @@ require 'sidekiq' require 'sidekiq-poison-pill-remedy' +Dir[File.join(__dir__, 'support', '**', '*.rb')].each { |f| require f } + RSpec.configure do |config| + Sidekiq::Testing.inline! # Enable flags like --only-failures and --next-failure config.example_status_persistence_file_path = '.rspec_status' @@ -21,6 +24,4 @@ config.before(:all) do ENV['REDIS_URL'] ||= 'redis://localhost:6379/1' end - - Dir[File.join(__dir__, 'support', '**', '*.rb')].each { |f| require f } end diff --git a/spec/support/my_job.rb b/spec/support/my_job.rb index d2cf526..e8b2b9a 100644 --- a/spec/support/my_job.rb +++ b/spec/support/my_job.rb @@ -1,7 +1,13 @@ class MyJob - include Sidekiq::Worker + include Sidekiq::Job + sidekiq_options retry: 0 def perform(arg) - raise 'An error occurred!' if arg == 'fail' + if arg == 'fail' + Sidekiq.logger.error('Forced failure for testing') + + else + 'surprise' + end end end From f1a192e463ed9e7d6e3d50d6ee7045b92e9dad2b Mon Sep 17 00:00:00 2001 From: Robert Gradowski Date: Thu, 24 Oct 2024 14:52:10 +0200 Subject: [PATCH 07/14] another spec version --- .gitignore | 1 + .rubocop.yml | 114 +++++++++++++++++++++++- Gemfile | 20 +++-- Gemfile.lock | 94 ------------------- README.md | 5 ++ Rakefile | 4 +- lib/jobs/my_job.rb | 12 +++ lib/sidekiq-poison-pill-remedy.rb | 2 +- lib/sidekiq_poison_pill_remedy.rb | 6 +- lib/sidekiq_worker_loader.rb | 8 ++ lib/version.rb | 2 +- sidekiq-poison-pill-remedy.gemspec | 29 +++--- spec/sidekiq_poison_pill_remedy_spec.rb | 47 +++++----- spec/spec_helper.rb | 18 ++-- spec/support/my_job.rb | 11 +-- 15 files changed, 208 insertions(+), 165 deletions(-) delete mode 100644 Gemfile.lock create mode 100644 lib/jobs/my_job.rb create mode 100644 lib/sidekiq_worker_loader.rb diff --git a/.gitignore b/.gitignore index 541570a..1c05247 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ # rspec failure tracking .rspec_status +# Ignore Gemfile.lock Gemfile.lock \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml index 2b9e324..6aee70e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,8 +1,114 @@ -Style/Documentation: - Enabled: false +require: + - rubocop-performance + - rubocop-rspec + +inherit_mode: + merge: + - Exclude + AllCops: NewCops: enable + TargetRubyVersion: 3.1 + Exclude: + - "db/**/*" + - "bin/**/*" + - "tmp/**/*" + - "log/**/*" + - "vendor/**/*" + - "spec/rails_helper.rb" + +Layout/FrozenStringLiteralComment: + Enabled: true + +Layout/ArgumentAlignment: + EnforcedStyle: with_fixed_indentation + +Layout/ArrayAlignment: + EnforcedStyle: with_fixed_indentation + +Layout/EmptyLineBetweenDefs: + AllowAdjacentOneLineDefs: true + +Layout/EndAlignment: + EnforcedStyleAlignWith: variable + +Layout/FirstArgumentIndentation: + EnforcedStyle: consistent + +Layout/FirstArrayElementIndentation: + EnforcedStyle: consistent + +Layout/FirstHashElementIndentation: + EnforcedStyle: consistent + +Layout/MultilineMethodCallIndentation: + EnforcedStyle: indented + +Layout/MultilineOperationIndentation: + EnforcedStyle: indented + +Layout/ParameterAlignment: + EnforcedStyle: with_fixed_indentation + +Layout/SpaceBeforeBrackets: + Enabled: false + + +Lint/UnusedMethodArgument: + AllowUnusedKeywordArguments: true + +Lint/AmbiguousBlockAssociation: + Exclude: + - 'spec/**/*' + + +Naming/FileName: + EnforcedStyle: snake_case + Exclude: + - 'lib/sidekiq-poison-pill-remedy.rb' + +Naming/VariableNumber: + EnforcedStyle: snake_case + + +RSpec/MultipleExpectations: + Max: 20 + +RSpec/NestedGroups: + Max: 10 + +RSpec/ExampleLength: + Max: 15 + Exclude: + - 'spec/sidekiq_poison_pill_remedy_spec.rb' + +RSpec/VerifiedDoubles: + Exclude: + - 'spec/**/*.rb' + + Metrics/AbcSize: - Max: 19 + Max: 15 + Exclude: + - 'lib/sidekiq_poison_pill_remedy.rb' + + Metrics/MethodLength: - Max: 20 \ No newline at end of file + Max: 20 + +Metrics/BlockLength: + Exclude: + - 'lib/sidekiq_poison_pill_remedy.rb' + +Layout/LineLength: + Max: 125 + + +Style/StringLiterals: + EnforcedStyle: double_quotes + ConsistentQuotesInMultiline: true + +Style/Documentation: + Enabled: false + + diff --git a/Gemfile b/Gemfile index 7d28ee2..9b5a7c8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,14 +1,18 @@ # frozen_string_literal: true -source 'https://rubygems.org' +source "https://rubygems.org" # Specify your gem's dependencies in sidekiq-poison-pill-remedy.gemspec gemspec -gem 'rake', '~> 13.0' -gem 'rspec', '~> 3.0' -gem 'rubocop', '~> 1.40', require: false -gem 'rubocop-performance' -gem 'rubocop-rake' -gem 'rubocop-rspec' -gem 'sentry-ruby' +gem "rake", "~> 13.0" +gem "sentry-ruby" + +group :development, :test do + gem "rspec", "~> 3.0" + gem "rspec-sidekiq" + gem "rubocop", "~> 1.40", require: false + gem "rubocop-performance" + gem "rubocop-rake" + gem "rubocop-rspec" +end diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index abcb94b..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,94 +0,0 @@ -PATH - remote: . - specs: - sidekiq-poison-pill-remedy (0.1.0) - sidekiq - -GEM - remote: https://rubygems.org/ - specs: - ast (2.4.2) - bigdecimal (3.1.8) - concurrent-ruby (1.3.4) - connection_pool (2.4.1) - diff-lcs (1.5.1) - json (2.7.2) - language_server-protocol (3.17.0.3) - logger (1.6.1) - parallel (1.26.3) - parser (3.3.5.0) - ast (~> 2.4.1) - racc - racc (1.8.1) - rack (3.1.7) - rainbow (3.1.1) - rake (13.2.1) - redis-client (0.22.2) - connection_pool - regexp_parser (2.9.2) - rspec (3.13.0) - rspec-core (~> 3.13.0) - rspec-expectations (~> 3.13.0) - rspec-mocks (~> 3.13.0) - rspec-core (3.13.1) - rspec-support (~> 3.13.0) - rspec-expectations (3.13.3) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.13.0) - rspec-mocks (3.13.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.13.0) - rspec-sidekiq (5.0.0) - rspec-core (~> 3.0) - rspec-expectations (~> 3.0) - rspec-mocks (~> 3.0) - sidekiq (>= 5, < 8) - rspec-support (3.13.1) - rubocop (1.66.1) - json (~> 2.3) - language_server-protocol (>= 3.17.0) - parallel (~> 1.10) - parser (>= 3.3.0.2) - rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 2.4, < 3.0) - rubocop-ast (>= 1.32.2, < 2.0) - ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.32.3) - parser (>= 3.3.1.0) - rubocop-performance (1.22.1) - rubocop (>= 1.48.1, < 2.0) - rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rake (0.6.0) - rubocop (~> 1.0) - rubocop-rspec (3.1.0) - rubocop (~> 1.61) - ruby-progressbar (1.13.0) - sentry-ruby (5.21.0) - bigdecimal - concurrent-ruby (~> 1.0, >= 1.0.2) - sidekiq (7.3.2) - concurrent-ruby (< 2) - connection_pool (>= 2.3.0) - logger - rack (>= 2.2.4) - redis-client (>= 0.22.2) - unicode-display_width (2.6.0) - -PLATFORMS - arm64-darwin-22 - x86_64-linux - -DEPENDENCIES - rake (~> 13.0) - rspec (~> 3.0) - rspec-sidekiq - rubocop (~> 1.40) - rubocop-performance - rubocop-rake - rubocop-rspec - sentry-ruby - sidekiq-poison-pill-remedy! - -BUNDLED WITH - 2.4.18 diff --git a/README.md b/README.md index fb45eab..a917967 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,13 @@ Or install it yourself as: The gem is supposed to be used in the following way when added to the application +Check Sidekiq super_fetch:[here](https://github.com/sidekiq/sidekiq/wiki/Reliability#using-super_fetch) + +Remedy is supposed to be use like: `config.super_fetch!(&SidekiqPoisonPillRemedy.remedy)` +When a job fails, the SidekiqPoisonPillRemedy captures the failure and determines whether the job should be moved to a dedicated poison_pill queue. + ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. diff --git a/Rakefile b/Rakefile index 82bb534..b6ae734 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'bundler/gem_tasks' -require 'rspec/core/rake_task' +require "bundler/gem_tasks" +require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) diff --git a/lib/jobs/my_job.rb b/lib/jobs/my_job.rb new file mode 100644 index 0000000..9d95ee1 --- /dev/null +++ b/lib/jobs/my_job.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require "sidekiq" + +class MyJob + include Sidekiq::Job + sidekiq_options retry: 1 + + def perform(arg) + raise StandardError, "Forced failure for testing" if arg == "fail" + end +end diff --git a/lib/sidekiq-poison-pill-remedy.rb b/lib/sidekiq-poison-pill-remedy.rb index 78c0ba0..bd456f4 100644 --- a/lib/sidekiq-poison-pill-remedy.rb +++ b/lib/sidekiq-poison-pill-remedy.rb @@ -1,3 +1,3 @@ # frozen_string_literal: true -require 'sidekiq_poison_pill_remedy' +require "sidekiq_poison_pill_remedy" diff --git a/lib/sidekiq_poison_pill_remedy.rb b/lib/sidekiq_poison_pill_remedy.rb index 60e2331..bc74ca7 100644 --- a/lib/sidekiq_poison_pill_remedy.rb +++ b/lib/sidekiq_poison_pill_remedy.rb @@ -7,7 +7,7 @@ def self.remedy job = Sidekiq::DeadSet.new.find_job(pill.jid) - if job.queue == 'poison_pill' + if job.queue == "poison_pill" capture_sentry_message( "#{job.klass} failed in the `#{job.queue}`, this means that it has to be urgently optimized on memory usage", level: :critical, @@ -29,8 +29,8 @@ def self.capture_sentry_message(message, level:, job_item:) if defined?(Sentry) Sentry.capture_message( message, - level: level, - extra: { job_item: job_item } + level:, + extra: { job_item: } ) end diff --git a/lib/sidekiq_worker_loader.rb b/lib/sidekiq_worker_loader.rb new file mode 100644 index 0000000..3e8444b --- /dev/null +++ b/lib/sidekiq_worker_loader.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +require "sidekiq" +require "sidekiq/api" +require "sidekiq/testing" +require "rspec-sidekiq" +require "sidekiq-poison-pill-remedy" +require_relative "jobs/my_job" diff --git a/lib/version.rb b/lib/version.rb index 214cd96..921083c 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -3,5 +3,5 @@ module SidekiqPoisonPillRemedy module Version end - VERSION = '0.1.0' + VERSION = "0.1.0" end diff --git a/sidekiq-poison-pill-remedy.gemspec b/sidekiq-poison-pill-remedy.gemspec index 577a744..5896b3e 100644 --- a/sidekiq-poison-pill-remedy.gemspec +++ b/sidekiq-poison-pill-remedy.gemspec @@ -1,22 +1,22 @@ # frozen_string_literal: true -require_relative 'lib/version' +require_relative "lib/version" Gem::Specification.new do |spec| - spec.name = 'sidekiq-poison-pill-remedy' + spec.name = "sidekiq-poison-pill-remedy" spec.version = SidekiqPoisonPillRemedy::VERSION - spec.authors = ['Karol Galanciak'] - spec.email = ['karol.galanciak@gmail.com'] + spec.authors = ["Karol Galanciak"] + spec.email = ["karol.galanciak@gmail.com"] spec.summary = "Enhances Sidekiq's job processing by automatically handling and rescheduling poison pills" spec.description = "Enhances Sidekiq's job processing by automatically handling and rescheduling poison pills" - spec.homepage = 'https://github.com/BookingSync/sidekiq-poison-pill-remedy' - spec.license = 'MIT' - spec.required_ruby_version = '>= 3.0.0' + spec.homepage = "https://github.com/BookingSync/sidekiq-poison-pill-remedy" + spec.license = "MIT" + spec.required_ruby_version = ">= 3.1.0" - spec.metadata['homepage_uri'] = spec.homepage - spec.metadata['source_code_uri'] = 'https://github.com/BookingSync/sidekiq-poison-pill-remedy' - spec.metadata['changelog_uri'] = 'https://github.com/BookingSync/sidekiq-poison-pill-remedy/blob/master/CHANGELOG.md' + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = "https://github.com/BookingSync/sidekiq-poison-pill-remedy" + spec.metadata["changelog_uri"] = "https://github.com/BookingSync/sidekiq-poison-pill-remedy/blob/master/CHANGELOG.md" # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. @@ -27,16 +27,15 @@ Gem::Specification.new do |spec| f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile]) end end - spec.bindir = 'exe' + spec.bindir = "exe" spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } - spec.require_paths = ['lib'] + spec.require_paths = ["lib"] # Uncomment to register a new dependency of your gem # spec.add_dependency "example-gem", "~> 1.0" - spec.add_dependency 'sidekiq' - spec.add_development_dependency 'rspec-sidekiq' + spec.add_dependency "sidekiq" # For more information and examples about making a new gem, check out our # guide at: https://bundler.io/guides/creating_gem.html - spec.metadata['rubygems_mfa_required'] = 'true' + spec.metadata["rubygems_mfa_required"] = "true" end diff --git a/spec/sidekiq_poison_pill_remedy_spec.rb b/spec/sidekiq_poison_pill_remedy_spec.rb index 20cbef6..858bae5 100644 --- a/spec/sidekiq_poison_pill_remedy_spec.rb +++ b/spec/sidekiq_poison_pill_remedy_spec.rb @@ -1,41 +1,46 @@ # frozen_string_literal: true -require 'sidekiq/testing' -require 'rspec-sidekiq' -require 'sidekiq' -require 'sidekiq-poison-pill-remedy' -require 'support/my_job' -require 'sidekiq/api' +require "sidekiq" +require "sidekiq/api" +require "sidekiq/testing" +require "rspec-sidekiq" +require "sidekiq-poison-pill-remedy" +require "support/my_job" RSpec.describe SidekiqPoisonPillRemedy do before do - Sidekiq::Testing.fake! + Sidekiq::Testing.inline! + allow(Sentry).to receive(:capture_message) end - it 'moves job to poison_pill queue and logs message' do - puts '1' - jid = MyJob.perform_async('fail') + + it "moves job to poison_pill queue and logs message" do + puts "1" + + jid = nil + expect do + jid = MyJob.perform_async("fail") + end.to raise_error(StandardError, "Forced failure for testing") + puts "Jobs in Queue: #{Sidekiq::Queue.new.size}" puts "DeadSet size: #{Sidekiq::DeadSet.new.size}" - puts '2' - MyJob.drain - puts '3' + puts "Jobs in DeadSet after processing: #{Sidekiq::DeadSet.new.size}" - job = Sidekiq::DeadSet.new.find_job(jid) - puts '4' - puts "Job JID: #{jid}" - puts "DeadSet size: #{Sidekiq::DeadSet.new.size}" + dead_set = Sidekiq::DeadSet.new + expect(dead_set.size).to eq(1) + job = dead_set.find_job(jid) + puts "4" + puts "Job JID: #{jid}" expect(job).not_to be_nil - expect(job.klass).to eq('MyJob') + expect(job.klass).to eq("MyJob") - SidekiqPoisonPillRemedy.remedy.call(nil, job) + expect { described_class.remedy.call(nil, job) }.not_to raise_error puts "DeadSet jobs: #{Sidekiq::DeadSet.new.size}" puts "Queue jobs: #{Sidekiq::Queue.new.size}" - puts "Job JID: #{jid}" - poison_pill_job = Sidekiq::Queue.new('poison_pill').find_job(job.jid) + poison_pill_job = Sidekiq::Queue.new("poison_pill").find_job(job.jid) expect(poison_pill_job).not_to be_nil puts "Poison Pill Job JID: #{poison_pill_job.jid}" end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 439897b..fad5a51 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true -require 'bundler/setup' -require 'sidekiq/testing' -require 'rspec-sidekiq' -require 'sentry-ruby' -require 'sidekiq' -require 'sidekiq-poison-pill-remedy' +require "bundler/setup" +require "sidekiq/testing" +require "rspec-sidekiq" +require "sentry-ruby" +require "sidekiq" +require "sidekiq-poison-pill-remedy" -Dir[File.join(__dir__, 'support', '**', '*.rb')].each { |f| require f } +Dir[File.join(__dir__, "support", "**", "*.rb")].each { |f| require f } RSpec.configure do |config| Sidekiq::Testing.inline! # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = '.rspec_status' + config.example_status_persistence_file_path = ".rspec_status" # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! @@ -22,6 +22,6 @@ end config.before(:all) do - ENV['REDIS_URL'] ||= 'redis://localhost:6379/1' + ENV["REDIS_URL"] ||= "redis://localhost:6379/1" end end diff --git a/spec/support/my_job.rb b/spec/support/my_job.rb index e8b2b9a..0137189 100644 --- a/spec/support/my_job.rb +++ b/spec/support/my_job.rb @@ -1,13 +1,10 @@ +# frozen_string_literal: true + class MyJob include Sidekiq::Job - sidekiq_options retry: 0 + sidekiq_options retry: 3 def perform(arg) - if arg == 'fail' - Sidekiq.logger.error('Forced failure for testing') - - else - 'surprise' - end + raise StandardError, "Forced failure for testing" if arg == "fail" end end From 20e5c7f7e890f579b2de33e698fb28cdd199bb6e Mon Sep 17 00:00:00 2001 From: Robert Gradowski Date: Thu, 24 Oct 2024 17:10:55 +0200 Subject: [PATCH 08/14] spec changed according to last comment --- lib/sidekiq_worker_loader.rb | 8 ++++++ spec/sidekiq_poison_pill_remedy_spec.rb | 36 +++++++++---------------- spec/spec_helper.rb | 2 +- spec/support/my_job.rb | 6 ++++- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/sidekiq_worker_loader.rb b/lib/sidekiq_worker_loader.rb index 3e8444b..7fcf196 100644 --- a/lib/sidekiq_worker_loader.rb +++ b/lib/sidekiq_worker_loader.rb @@ -6,3 +6,11 @@ require "rspec-sidekiq" require "sidekiq-poison-pill-remedy" require_relative "jobs/my_job" + +Sidekiq.configure_server do |config| + config.redis = { url: ENV['REDIS_URL'] || 'redis://localhost:6379/0' } +end + +Sidekiq.configure_client do |config| + config.redis = { url: ENV['REDIS_URL'] || 'redis://localhost:6379/0' } +end diff --git a/spec/sidekiq_poison_pill_remedy_spec.rb b/spec/sidekiq_poison_pill_remedy_spec.rb index 858bae5..526af06 100644 --- a/spec/sidekiq_poison_pill_remedy_spec.rb +++ b/spec/sidekiq_poison_pill_remedy_spec.rb @@ -9,39 +9,27 @@ RSpec.describe SidekiqPoisonPillRemedy do before do - Sidekiq::Testing.inline! - allow(Sentry).to receive(:capture_message) + Sidekiq::Testing.fake! end it "moves job to poison_pill queue and logs message" do - puts "1" + puts "Starting test..." - jid = nil - expect do - jid = MyJob.perform_async("fail") - end.to raise_error(StandardError, "Forced failure for testing") + job_id = MyJob.perform_async(nil) - puts "Jobs in Queue: #{Sidekiq::Queue.new.size}" - puts "DeadSet size: #{Sidekiq::DeadSet.new.size}" - - puts "Jobs in DeadSet after processing: #{Sidekiq::DeadSet.new.size}" - dead_set = Sidekiq::DeadSet.new - expect(dead_set.size).to eq(1) - job = dead_set.find_job(jid) + expect(Sidekiq::Queue.new.size).to eq(1) + expect(Sidekiq::Queue.new("poison_pill").size).to eq(0) + puts "2" - puts "4" - puts "Job JID: #{jid}" - expect(job).not_to be_nil - expect(job.klass).to eq("MyJob") + job = Sidekiq::Queue.new.find_job(job_id) - expect { described_class.remedy.call(nil, job) }.not_to raise_error + SidekiqPoisonPillRemedy.remedy.call(nil, job) - puts "DeadSet jobs: #{Sidekiq::DeadSet.new.size}" - puts "Queue jobs: #{Sidekiq::Queue.new.size}" + puts "Jobs in Queue: #{Sidekiq::Queue.new.size}" + puts "3" - poison_pill_job = Sidekiq::Queue.new("poison_pill").find_job(job.jid) - expect(poison_pill_job).not_to be_nil - puts "Poison Pill Job JID: #{poison_pill_job.jid}" + expect(Sidekiq::Queue.new.size).to eq(0) + expect(Sidekiq::Queue.new("poison_pill").size).to eq(1) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fad5a51..70faa9a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,7 +10,7 @@ Dir[File.join(__dir__, "support", "**", "*.rb")].each { |f| require f } RSpec.configure do |config| - Sidekiq::Testing.inline! + Sidekiq::Testing.fake! # Enable flags like --only-failures and --next-failure config.example_status_persistence_file_path = ".rspec_status" diff --git a/spec/support/my_job.rb b/spec/support/my_job.rb index 0137189..c0d57c7 100644 --- a/spec/support/my_job.rb +++ b/spec/support/my_job.rb @@ -5,6 +5,10 @@ class MyJob sidekiq_options retry: 3 def perform(arg) - raise StandardError, "Forced failure for testing" if arg == "fail" + if arg.nil? + raise StandardError, "Job was called with nil argument" + else + puts "Job executed successfully with argument: #{arg}" + end end end From 35264bc7d2af68156c9c45a71d0d3d0a094f960a Mon Sep 17 00:00:00 2001 From: Karol Galanciak Date: Thu, 24 Oct 2024 18:22:18 +0200 Subject: [PATCH 09/14] write basic specs ; clean up setup and file structure --- .rubocop.yml | 3 +- lib/sidekiq-poison-pill-remedy.rb | 2 + lib/sidekiq_worker_loader.rb | 16 ------ sidekiq-poison-pill-remedy.gemspec | 1 + spec/sidekiq_poison_pill_remedy_spec.rb | 72 +++++++++++++++---------- spec/spec_helper.rb | 12 +++++ spec/support/my_job.rb | 8 ++- 7 files changed, 63 insertions(+), 51 deletions(-) delete mode 100644 lib/sidekiq_worker_loader.rb diff --git a/.rubocop.yml b/.rubocop.yml index 6aee70e..469aab1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -111,4 +111,5 @@ Style/StringLiterals: Style/Documentation: Enabled: false - +RSpec/AnyInstance: + Enabled: false diff --git a/lib/sidekiq-poison-pill-remedy.rb b/lib/sidekiq-poison-pill-remedy.rb index bd456f4..9625472 100644 --- a/lib/sidekiq-poison-pill-remedy.rb +++ b/lib/sidekiq-poison-pill-remedy.rb @@ -1,3 +1,5 @@ # frozen_string_literal: true require "sidekiq_poison_pill_remedy" +require "active_support" +require "active_support/inflector" diff --git a/lib/sidekiq_worker_loader.rb b/lib/sidekiq_worker_loader.rb deleted file mode 100644 index 7fcf196..0000000 --- a/lib/sidekiq_worker_loader.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require "sidekiq" -require "sidekiq/api" -require "sidekiq/testing" -require "rspec-sidekiq" -require "sidekiq-poison-pill-remedy" -require_relative "jobs/my_job" - -Sidekiq.configure_server do |config| - config.redis = { url: ENV['REDIS_URL'] || 'redis://localhost:6379/0' } -end - -Sidekiq.configure_client do |config| - config.redis = { url: ENV['REDIS_URL'] || 'redis://localhost:6379/0' } -end diff --git a/sidekiq-poison-pill-remedy.gemspec b/sidekiq-poison-pill-remedy.gemspec index 5896b3e..5f23c1c 100644 --- a/sidekiq-poison-pill-remedy.gemspec +++ b/sidekiq-poison-pill-remedy.gemspec @@ -33,6 +33,7 @@ Gem::Specification.new do |spec| # Uncomment to register a new dependency of your gem # spec.add_dependency "example-gem", "~> 1.0" + spec.add_dependency "activesupport", ">= 6.1" spec.add_dependency "sidekiq" # For more information and examples about making a new gem, check out our diff --git a/spec/sidekiq_poison_pill_remedy_spec.rb b/spec/sidekiq_poison_pill_remedy_spec.rb index 526af06..91f9029 100644 --- a/spec/sidekiq_poison_pill_remedy_spec.rb +++ b/spec/sidekiq_poison_pill_remedy_spec.rb @@ -1,35 +1,49 @@ # frozen_string_literal: true -require "sidekiq" -require "sidekiq/api" -require "sidekiq/testing" -require "rspec-sidekiq" -require "sidekiq-poison-pill-remedy" -require "support/my_job" +require "spec_helper" RSpec.describe SidekiqPoisonPillRemedy do - before do - Sidekiq::Testing.fake! - end - - it "moves job to poison_pill queue and logs message" do - puts "Starting test..." - - job_id = MyJob.perform_async(nil) - - - expect(Sidekiq::Queue.new.size).to eq(1) - expect(Sidekiq::Queue.new("poison_pill").size).to eq(0) - puts "2" - - job = Sidekiq::Queue.new.find_job(job_id) - - SidekiqPoisonPillRemedy.remedy.call(nil, job) - - puts "Jobs in Queue: #{Sidekiq::Queue.new.size}" - puts "3" - - expect(Sidekiq::Queue.new.size).to eq(0) - expect(Sidekiq::Queue.new("poison_pill").size).to eq(1) + describe ".remedy" do + subject(:call) { described_class.remedy.call(nil, job) } + + let(:default_queue) { "default" } + let(:poison_pill_queue) { "poison_pill" } + let(:enqueue_job) { MyJob.set(queue: job_queue).perform_async("fail") } + let(:job) { Sidekiq::Queue.new(default_queue).find_job(enqueue_job) } + + before do + Sidekiq::Testing.disable! + Sidekiq::Queue.new(poison_pill_queue).clear + Sidekiq::Queue.new(default_queue).clear + + enqueue_job + + # there is no easy way to move the job to DeadSet, the process is rather complex + # we would ideally execute a single method call have a proper setup but in that case + # we need to use stub + allow_any_instance_of(Sidekiq::DeadSet).to receive(:find_job).with(enqueue_job).and_return(job) + end + + context "when the job is a poison pill in non-poison pill queue" do + let(:job_queue) { default_queue } + + it "moves job to poison_pill queue and sends error notification" do + expect do + call + end.to change { Sidekiq::Queue.new(default_queue).count }.from(1).to(0) + .and change { Sidekiq::Queue.new(poison_pill_queue).count }.from(0).to(1) + end + end + + context "when the job is a poison pill in poison pill queue" do + let(:job_queue) { poison_pill_queue } + + it "keep the jobs in posion pill queue and sends error notification" do + expect do + call + end.to avoid_changing { Sidekiq::Queue.new(default_queue).count }.from(0) + .and avoid_changing { Sidekiq::Queue.new(poison_pill_queue).count }.from(1) + end + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 70faa9a..a830f93 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,7 +5,9 @@ require "rspec-sidekiq" require "sentry-ruby" require "sidekiq" +require "sidekiq/api" require "sidekiq-poison-pill-remedy" +require "support/my_job" Dir[File.join(__dir__, "support", "**", "*.rb")].each { |f| require f } @@ -24,4 +26,14 @@ config.before(:all) do ENV["REDIS_URL"] ||= "redis://localhost:6379/1" end + + Sidekiq.configure_server do |sidekiq_config| + sidekiq_config.redis = { url: ENV["REDIS_URL"] || "redis://localhost:6379/0" } + end + + Sidekiq.configure_client do |sidekiq_config| + sidekiq_config.redis = { url: ENV["REDIS_URL"] || "redis://localhost:6379/0" } + end + + RSpec::Matchers.define_negated_matcher :avoid_changing, :change end diff --git a/spec/support/my_job.rb b/spec/support/my_job.rb index c0d57c7..b4661e3 100644 --- a/spec/support/my_job.rb +++ b/spec/support/my_job.rb @@ -5,10 +5,8 @@ class MyJob sidekiq_options retry: 3 def perform(arg) - if arg.nil? - raise StandardError, "Job was called with nil argument" - else - puts "Job executed successfully with argument: #{arg}" - end + raise StandardError, "Job was called with nil argument" if arg.nil? + + puts "Job executed successfully with argument: #{arg}" end end From 617268a86821dd7a9931d6b3b945420b5d4c9230 Mon Sep 17 00:00:00 2001 From: Robert Gradowski Date: Fri, 25 Oct 2024 16:58:26 +0200 Subject: [PATCH 10/14] Sentry message --- spec/sidekiq_poison_pill_remedy_spec.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/spec/sidekiq_poison_pill_remedy_spec.rb b/spec/sidekiq_poison_pill_remedy_spec.rb index 91f9029..100993f 100644 --- a/spec/sidekiq_poison_pill_remedy_spec.rb +++ b/spec/sidekiq_poison_pill_remedy_spec.rb @@ -18,10 +18,8 @@ enqueue_job - # there is no easy way to move the job to DeadSet, the process is rather complex - # we would ideally execute a single method call have a proper setup but in that case - # we need to use stub allow_any_instance_of(Sidekiq::DeadSet).to receive(:find_job).with(enqueue_job).and_return(job) + allow(Sentry).to receive(:capture_message) end context "when the job is a poison pill in non-poison pill queue" do @@ -32,6 +30,12 @@ call end.to change { Sidekiq::Queue.new(default_queue).count }.from(1).to(0) .and change { Sidekiq::Queue.new(poison_pill_queue).count }.from(0).to(1) + + expect(Sentry).to have_received(:capture_message).with( + "MyJob was marked as `poison pill`, please create the job memory optimizations ticket timely", + level: :warning, + extra: hash_including(:job_item) + ) end end @@ -43,6 +47,12 @@ call end.to avoid_changing { Sidekiq::Queue.new(default_queue).count }.from(0) .and avoid_changing { Sidekiq::Queue.new(poison_pill_queue).count }.from(1) + + expect(Sentry).to have_received(:capture_message).with( + "MyJob failed in the `poison_pill`, this means that it has to be urgently optimized on memory usage", + level: :critical, + extra: hash_including(:job_item) + ) end end end From d57952dbed0a9233efe966d1124597ce5659999b Mon Sep 17 00:00:00 2001 From: Robert Gradowski Date: Fri, 25 Oct 2024 17:31:33 +0200 Subject: [PATCH 11/14] Sentry spec fix --- spec/sidekiq_poison_pill_remedy_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/sidekiq_poison_pill_remedy_spec.rb b/spec/sidekiq_poison_pill_remedy_spec.rb index 100993f..3b655e0 100644 --- a/spec/sidekiq_poison_pill_remedy_spec.rb +++ b/spec/sidekiq_poison_pill_remedy_spec.rb @@ -9,7 +9,7 @@ let(:default_queue) { "default" } let(:poison_pill_queue) { "poison_pill" } let(:enqueue_job) { MyJob.set(queue: job_queue).perform_async("fail") } - let(:job) { Sidekiq::Queue.new(default_queue).find_job(enqueue_job) } + let(:job) { Sidekiq::Queue.new(job_queue).find_job(enqueue_job) } before do Sidekiq::Testing.disable! @@ -19,7 +19,7 @@ enqueue_job allow_any_instance_of(Sidekiq::DeadSet).to receive(:find_job).with(enqueue_job).and_return(job) - allow(Sentry).to receive(:capture_message) + allow(Sentry).to receive(:capture_message).and_call_original end context "when the job is a poison pill in non-poison pill queue" do @@ -43,6 +43,8 @@ let(:job_queue) { poison_pill_queue } it "keep the jobs in posion pill queue and sends error notification" do + expect(job.queue).to eq("poison_pill") + expect do call end.to avoid_changing { Sidekiq::Queue.new(default_queue).count }.from(0) From 2d318311be31ecfaa21e2c54282e3da0655cd563 Mon Sep 17 00:00:00 2001 From: Robert Gradowski Date: Mon, 28 Oct 2024 11:24:04 +0100 Subject: [PATCH 12/14] added logging test --- spec/sidekiq_poison_pill_remedy_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/sidekiq_poison_pill_remedy_spec.rb b/spec/sidekiq_poison_pill_remedy_spec.rb index 3b655e0..a2845fb 100644 --- a/spec/sidekiq_poison_pill_remedy_spec.rb +++ b/spec/sidekiq_poison_pill_remedy_spec.rb @@ -20,6 +20,7 @@ allow_any_instance_of(Sidekiq::DeadSet).to receive(:find_job).with(enqueue_job).and_return(job) allow(Sentry).to receive(:capture_message).and_call_original + allow(Sidekiq.logger).to receive(:fatal) end context "when the job is a poison pill in non-poison pill queue" do @@ -36,6 +37,9 @@ level: :warning, extra: hash_including(:job_item) ) + expect(Sidekiq.logger).to have_received(:fatal).with( + "MyJob was marked as `poison pill`, please create the job memory optimizations ticket timely" + ) end end @@ -55,6 +59,9 @@ level: :critical, extra: hash_including(:job_item) ) + expect(Sidekiq.logger).to have_received(:fatal).with( + "MyJob failed in the `poison_pill`, this means that it has to be urgently optimized on memory usage" + ) end end end From 80968213f4b10e4acfb05c56988c54dc3e8e8779 Mon Sep 17 00:00:00 2001 From: Robert Gradowski Date: Mon, 28 Oct 2024 12:18:57 +0100 Subject: [PATCH 13/14] readme edit, lib/jobs delete --- README.md | 2 +- lib/jobs/my_job.rb | 12 ------------ spec/spec_helper.rb | 1 - 3 files changed, 1 insertion(+), 14 deletions(-) delete mode 100644 lib/jobs/my_job.rb diff --git a/README.md b/README.md index a917967..7e90303 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Check Sidekiq super_fetch:[here](https://github.com/sidekiq/sidekiq/wiki/Reliabi Remedy is supposed to be use like: `config.super_fetch!(&SidekiqPoisonPillRemedy.remedy)` -When a job fails, the SidekiqPoisonPillRemedy captures the failure and determines whether the job should be moved to a dedicated poison_pill queue. +When a job is considered a poison pill by Sidekiq, SidekiqPoisonPillRemedy prevents it from being moved to DeadSet and moves it to a dedicated queue to make sure the job will be processed after capturing team's attention with Sentry notification ## Development diff --git a/lib/jobs/my_job.rb b/lib/jobs/my_job.rb deleted file mode 100644 index 9d95ee1..0000000 --- a/lib/jobs/my_job.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -require "sidekiq" - -class MyJob - include Sidekiq::Job - sidekiq_options retry: 1 - - def perform(arg) - raise StandardError, "Forced failure for testing" if arg == "fail" - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a830f93..064984c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,7 +12,6 @@ Dir[File.join(__dir__, "support", "**", "*.rb")].each { |f| require f } RSpec.configure do |config| - Sidekiq::Testing.fake! # Enable flags like --only-failures and --next-failure config.example_status_persistence_file_path = ".rspec_status" From e3489202cd22773f3538758a7c720a414198db5d Mon Sep 17 00:00:00 2001 From: Robert Gradowski Date: Mon, 28 Oct 2024 19:48:21 +0100 Subject: [PATCH 14/14] and_call_original fix in spec --- spec/sidekiq_poison_pill_remedy_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/sidekiq_poison_pill_remedy_spec.rb b/spec/sidekiq_poison_pill_remedy_spec.rb index a2845fb..d98e4fc 100644 --- a/spec/sidekiq_poison_pill_remedy_spec.rb +++ b/spec/sidekiq_poison_pill_remedy_spec.rb @@ -20,7 +20,7 @@ allow_any_instance_of(Sidekiq::DeadSet).to receive(:find_job).with(enqueue_job).and_return(job) allow(Sentry).to receive(:capture_message).and_call_original - allow(Sidekiq.logger).to receive(:fatal) + allow(Sidekiq.logger).to receive(:fatal).and_call_original end context "when the job is a poison pill in non-poison pill queue" do