From 88e39f2aa0d5a875d1836e4f6ef4bcc121cdce5e Mon Sep 17 00:00:00 2001 From: Dominik Menke Date: Thu, 8 Aug 2024 09:30:39 +0800 Subject: [PATCH] BREAKING: support Sidekiq 7+ This removes support for Sidekiq < 6.5 and Ruby < 3.0. --- .github/workflows/ci.yml | 11 +++++++++-- CHANGELOG.md | 5 +++++ lib/mini_scheduler.rb | 13 ++----------- lib/mini_scheduler/manager.rb | 4 ++-- mini_scheduler.gemspec | 4 ++-- spec/mini_scheduler/manager_spec.rb | 6 +++--- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3c1726e..fed6e9a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,7 @@ on: push: branches: - main + - sidekiq-7 jobs: lint: @@ -28,18 +29,24 @@ jobs: bundle exec stree check Gemfile $(git ls-files '*.rb') $(git ls-files '*.rake') $(git ls-files '*.thor') test: + name: Ruby ${{ matrix.ruby }}/Sidekiq ${{ matrix.sidekiq }}/Redis ${{ matrix.redis }} runs-on: ubuntu-latest timeout-minutes: 5 services: redis: - image: redis + image: ${{ matrix.redis }} ports: - 6379:6379 strategy: matrix: - ruby: ["3.1", "3.2", "3.3"] + ruby: ["3.0", "3.1", "3.2", "3.3"] + redis: ["redis", "valkey/valkey"] + sidekiq: ["6.5", "7.0", "7.1", "7.2", "7.3"] + + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/sidekiq-${{ matrix.sidekiq }}.gemfile steps: - uses: actions/checkout@v4 diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b2667e..f8cf796 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# next + +- Remove support for Sidekiq < 6.5 +- Update minimum Ruby version to 3.0 + # 0.17.0 - 2024-08-06 - Add `MiniScheduler::Manager.discover_running_scheduled_jobs` API to allow running scheduled jobs to easily be discovered on the diff --git a/lib/mini_scheduler.rb b/lib/mini_scheduler.rb index fbf217b..e6bea57 100644 --- a/lib/mini_scheduler.rb +++ b/lib/mini_scheduler.rb @@ -5,6 +5,7 @@ require "mini_scheduler/manager" require "mini_scheduler/distributed_mutex" require "sidekiq" +require "redis" begin require "sidekiq/exception_handler" @@ -16,16 +17,6 @@ def self.configure yield self end - class SidekiqExceptionHandler - if defined?(Sidekiq::ExceptionHandler) - extend Sidekiq::ExceptionHandler - else - def self.handle_exception(exception, context) - Sidekiq.handle_exception(exception, context) - end - end - end - def self.job_exception_handler(&blk) @job_exception_handler = blk if blk @job_exception_handler @@ -35,7 +26,7 @@ def self.handle_job_exception(ex, context = {}) if job_exception_handler job_exception_handler.call(ex, context) else - SidekiqExceptionHandler.handle_exception(ex, context) + Sidekiq.default_configuration.handle_exception(ex, context) end end diff --git a/lib/mini_scheduler/manager.rb b/lib/mini_scheduler/manager.rb index 1b1cd4a..a05513b 100644 --- a/lib/mini_scheduler/manager.rb +++ b/lib/mini_scheduler/manager.rb @@ -394,10 +394,10 @@ def self.hostname begin require "socket" Socket.gethostname - rescue => e + rescue StandardError begin `hostname`.strip - rescue => e + rescue StandardError "unknown_host" end end diff --git a/mini_scheduler.gemspec b/mini_scheduler.gemspec index 67e7423..2bcab88 100644 --- a/mini_scheduler.gemspec +++ b/mini_scheduler.gemspec @@ -15,12 +15,12 @@ Gem::Specification.new do |spec| spec.homepage = "https://github.com/discourse/mini_scheduler" spec.license = "MIT" - spec.required_ruby_version = ">= 2.7.0" + spec.required_ruby_version = ">= 3.0.0" spec.files = `git ls-files`.split($/).reject { |s| s =~ /^(spec|\.)/ } spec.require_paths = ["lib"] - spec.add_runtime_dependency "sidekiq", ">= 4.2.3", "< 7.0" + spec.add_runtime_dependency "sidekiq", ">= 6.5", "< 8.0" spec.add_development_dependency "pg", "~> 1.0" spec.add_development_dependency "activesupport", "~> 7.0" diff --git a/spec/mini_scheduler/manager_spec.rb b/spec/mini_scheduler/manager_spec.rb index 5491a99..821c848 100644 --- a/spec/mini_scheduler/manager_spec.rb +++ b/spec/mini_scheduler/manager_spec.rb @@ -418,7 +418,7 @@ def expect_job_failure(ex, ctx) class TempSidekiqLogger attr_accessor :exception, :context - def call(ex, ctx) + def call(ex, ctx, _component) self.exception = ex self.context = ctx end @@ -426,9 +426,9 @@ def call(ex, ctx) let(:logger) { TempSidekiqLogger.new } - before { Sidekiq.error_handlers << logger } + before { Sidekiq.default_configuration.error_handlers << logger } - after { Sidekiq.error_handlers.delete(logger) } + after { Sidekiq.default_configuration.error_handlers.delete(logger) } it "captures failed jobs" do manager.blocking_tick