From bd29b79929f520735ef806e963f454eec86f35fc Mon Sep 17 00:00:00 2001 From: Justin Hart Date: Mon, 19 Aug 2024 08:54:12 -0700 Subject: [PATCH 1/7] update tests --- .github/workflows/ci.yml | 4 ++-- resque-lock-timeout.gemspec | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8104243..b4ab754 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,13 +22,13 @@ jobs: strategy: fail-fast: false matrix: - ruby-version: ['2.7', '3.0', '3.1', '3.2'] + ruby-version: ['3.0', '3.1', '3.2', '3.3'] gemfile: ['Gemfile', 'Gemfile.redis3', 'Gemfile.redis4'] env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Ruby ${{ matrix.ruby-version }} uses: ruby/setup-ruby@v1 with: diff --git a/resque-lock-timeout.gemspec b/resque-lock-timeout.gemspec index 51d41f8..ab8f6a5 100644 --- a/resque-lock-timeout.gemspec +++ b/resque-lock-timeout.gemspec @@ -14,19 +14,20 @@ Gem::Specification.new do |s| s.add_dependency("resque", "~> 1.23") s.add_dependency("redis", ">= 3.3", "< 5") + s.add_development_dependency("rake") s.add_development_dependency("minitest") s.add_development_dependency("yard") s.add_development_dependency("simplecov") - s.description = < Date: Tue, 15 Oct 2024 14:25:00 -0700 Subject: [PATCH 2/7] matrix cleanup --- .github/workflows/ci.yml | 27 ++++++++++++++++++++++----- Gemfile | 36 ++++++++++++++++++++++++++++++++++++ Gemfile.redis3 | 5 ----- Gemfile.redis4 | 5 ----- Rakefile | 6 ++++++ test/lock_test.rb | 2 +- 6 files changed, 65 insertions(+), 16 deletions(-) delete mode 100644 Gemfile.redis3 delete mode 100644 Gemfile.redis4 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4ab754..27d9994 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,15 +18,32 @@ jobs: --health-retries 5 ports: # Maps port 6379 on service container to the host - - '6379:6379' + - "6379:6379" strategy: fail-fast: false matrix: - ruby-version: ['3.0', '3.1', '3.2', '3.3'] - gemfile: ['Gemfile', 'Gemfile.redis3', 'Gemfile.redis4'] + ruby-version: + - "3.0" + - "3.1" + - "3.2" + - "3.3" + resque-version: + - "~> 1.23" + redis-version: + - "~> 3.3" + - "~> 4.8" + resque-scheduler-version: + - "4.3.0" + - "< 4.9.0" + - "~> 4.9" + exclude: + # resque-scheduler (= 4.3.0) depends on redis (~> 3.3) + - redis-version: "~> 4.8" + resque-scheduler-version: "4.3.0" env: - # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps - BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }} + REDIS_VERSION: "${{ matrix.redis-version }}" + RESQUE: "${{ matrix.resque-version }}" + RESQUE_SCHEDULER_VERSION: "${{ matrix.resque-scheduler-version }}" steps: - uses: actions/checkout@v4 - name: Set up Ruby ${{ matrix.ruby-version }} diff --git a/Gemfile b/Gemfile index 851fabc..8c785c6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,38 @@ source 'https://rubygems.org' + +case resque_version = ENV.fetch('RESQUE', 'latest') +when 'master' + gem 'resque', git: 'https://github.com/resque/resque' +when /^git:/, /^https:/ + gem 'resque', git: resque_version +when 'latest' + gem 'resque' +else + gem 'resque', resque_version +end + +case redis_version = ENV.fetch('REDIS_VERSION', 'latest') +when 'master' + gem 'redis', git: 'https://github.com/redis/redis-rb' +when /^git:/, /^https:/ + gem 'redis', git: redis_version +when 'latest' + gem 'redis' +else + gem 'redis', redis_version +end + +case resque_scheduler_version = ENV.fetch('RESQUE_SCHEDULER_VERSION', 'none') +when 'master' + gem 'resque-scheduler', git: 'https://github.com/resque/resque-scheduler' +when /^git:/, /^https:/ + gem 'resque-scheduler', git: resque_scheduler_version +when 'latest' + gem 'resque-scheduler' +when 'none' + #noop +else + gem 'resque-scheduler', resque_scheduler_version +end + gemspec diff --git a/Gemfile.redis3 b/Gemfile.redis3 deleted file mode 100644 index 7283c0a..0000000 --- a/Gemfile.redis3 +++ /dev/null @@ -1,5 +0,0 @@ -source 'https://rubygems.org' -gemspec - -gem 'redis', '~> 3.3' -gem 'redis-namespace', '~> 1.5.3' diff --git a/Gemfile.redis4 b/Gemfile.redis4 deleted file mode 100644 index b19db31..0000000 --- a/Gemfile.redis4 +++ /dev/null @@ -1,5 +0,0 @@ -source 'https://rubygems.org' -gemspec - -gem 'redis', '~> 4.8' -gem 'redis-namespace', '~> 1.9' diff --git a/Rakefile b/Rakefile index 4ae1bf4..ff27e6b 100644 --- a/Rakefile +++ b/Rakefile @@ -10,6 +10,12 @@ Rake::TestTask.new(:test) do |task| task.verbose = true end +desc "Run resque-scheduler integration tests." +Rake::TestTask.new(:test_integration_resque_scheduler) do |task| + task.test_files = FileList["test/integration/resque-scheduler/*_test.rb"] + task.verbose = true +end + desc "Build Yardoc documentation." YARD::Rake::YardocTask.new :yardoc do |t| t.files = ["lib/**/*.rb"] diff --git a/test/lock_test.rb b/test/lock_test.rb index 1550188..a00188d 100644 --- a/test/lock_test.rb +++ b/test/lock_test.rb @@ -13,7 +13,7 @@ def test_resque_plugin_lint end def test_version - major, minor, _patch = Resque::Version.split(".") + major, minor, _patch = Resque::VERSION.split(".") assert_equal 1, major.to_i assert minor.to_i >= 7 end From b7c9f63ba0f6c49776d580e0e80cc5ced8ed0e6e Mon Sep 17 00:00:00 2001 From: Justin Hart Date: Tue, 15 Oct 2024 15:32:41 -0700 Subject: [PATCH 3/7] add integration tests --- .github/workflows/ci.yml | 12 +++--- Rakefile | 4 +- .../resque-scheduler/delayed_job_test.rb | 39 +++++++++++++++++++ 3 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 test/integration/resque-scheduler/delayed_job_test.rb diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 27d9994..9c585eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,6 +44,10 @@ jobs: REDIS_VERSION: "${{ matrix.redis-version }}" RESQUE: "${{ matrix.resque-version }}" RESQUE_SCHEDULER_VERSION: "${{ matrix.resque-scheduler-version }}" + # The hostname used to communicate with the Redis service container + REDIS_TEST_HOST: localhost + # The default Redis port + REDIS_TEST_PORT: 6379 steps: - uses: actions/checkout@v4 - name: Set up Ruby ${{ matrix.ruby-version }} @@ -52,9 +56,7 @@ jobs: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true - name: Run tests - env: - # The hostname used to communicate with the Redis service container - REDIS_TEST_HOST: localhost - # The default Redis port - REDIS_TEST_PORT: 6379 run: bundle exec rake + - name: Run integration tests + run: bundle exec rake test_integration + diff --git a/Rakefile b/Rakefile index ff27e6b..51dbfc1 100644 --- a/Rakefile +++ b/Rakefile @@ -11,8 +11,8 @@ Rake::TestTask.new(:test) do |task| end desc "Run resque-scheduler integration tests." -Rake::TestTask.new(:test_integration_resque_scheduler) do |task| - task.test_files = FileList["test/integration/resque-scheduler/*_test.rb"] +Rake::TestTask.new(:test_integration) do |task| + task.test_files = FileList["test/integration/**/*_test.rb"] task.verbose = true end diff --git a/test/integration/resque-scheduler/delayed_job_test.rb b/test/integration/resque-scheduler/delayed_job_test.rb new file mode 100644 index 0000000..363b780 --- /dev/null +++ b/test/integration/resque-scheduler/delayed_job_test.rb @@ -0,0 +1,39 @@ +require File.dirname(__FILE__) + "/../../test_helper" + +require 'resque-scheduler' + +def scheduler_version_compare(version) + Gem::Requirement.create(version).satisfied_by?(Gem::Version.create(Resque::Scheduler::VERSION)) +end + +class LockTest < Minitest::Test + def setup + $success = $lock_failed = $lock_expired = $enqueue_failed = 0 + Resque::Scheduler.quiet = true + Resque.redis.redis.flushall + @worker = Resque::Worker.new(:test) + # Resque::Scheduler.delayed_requeue_batch_size = 100 + end + + def test_delayed_item_enqueue + t = Time.now + 60 + + # Resque::Scheduler.expects(:enqueue_next_item).never + + # create 90 jobs + 90.times { Resque.enqueue_at(t, LonelyJob) } + assert_equal(90, Resque.delayed_timestamp_size(t)) + + Resque::Scheduler.enqueue_delayed_items_for_timestamp(t) + assert_equal(0, Resque.delayed_timestamp_size(t)) + + # assert that the active queue has the lonely job + if scheduler_version_compare('< 4.9') + assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) + else + # this is asserting that > 4.9 "fails" without the patch + assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob))) + end + end + +end From 07a836d7714ce1661acbb07dec155125152b6f9e Mon Sep 17 00:00:00 2001 From: Justin Hart Date: Wed, 16 Oct 2024 10:47:56 -0700 Subject: [PATCH 4/7] test our branch --- .github/workflows/ci.yml | 1 + Gemfile | 12 ++- .../resque-scheduler/delayed_job_test.rb | 93 ++++++++++++++++++- 3 files changed, 101 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c585eb..260ea1e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,7 @@ jobs: - "4.3.0" - "< 4.9.0" - "~> 4.9" + - "https://github.com/Ibotta/resque-scheduler.git@enqueue-multi-rollback" exclude: # resque-scheduler (= 4.3.0) depends on redis (~> 3.3) - redis-version: "~> 4.8" diff --git a/Gemfile b/Gemfile index 8c785c6..6e6648e 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,8 @@ when /^git:/, /^https:/ when 'latest' gem 'resque' else - gem 'resque', resque_version + versions = resque_version.split(',') + gem 'resque', *versions end case redis_version = ENV.fetch('REDIS_VERSION', 'latest') @@ -19,20 +20,23 @@ when /^git:/, /^https:/ when 'latest' gem 'redis' else - gem 'redis', redis_version + versions = redis_version.split(',') + gem 'redis', *versions end case resque_scheduler_version = ENV.fetch('RESQUE_SCHEDULER_VERSION', 'none') when 'master' gem 'resque-scheduler', git: 'https://github.com/resque/resque-scheduler' when /^git:/, /^https:/ - gem 'resque-scheduler', git: resque_scheduler_version + repo, ref = resque_scheduler_version.split('@', 2) + gem 'resque-scheduler', git: repo, ref: ref when 'latest' gem 'resque-scheduler' when 'none' #noop else - gem 'resque-scheduler', resque_scheduler_version + versions = resque_scheduler_version.split(',') + gem 'resque-scheduler', *versions end gemspec diff --git a/test/integration/resque-scheduler/delayed_job_test.rb b/test/integration/resque-scheduler/delayed_job_test.rb index 363b780..32dad92 100644 --- a/test/integration/resque-scheduler/delayed_job_test.rb +++ b/test/integration/resque-scheduler/delayed_job_test.rb @@ -12,7 +12,6 @@ def setup Resque::Scheduler.quiet = true Resque.redis.redis.flushall @worker = Resque::Worker.new(:test) - # Resque::Scheduler.delayed_requeue_batch_size = 100 end def test_delayed_item_enqueue @@ -30,10 +29,102 @@ def test_delayed_item_enqueue # assert that the active queue has the lonely job if scheduler_version_compare('< 4.9') assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) + elsif Resque::Scheduler::VERSION.end_with?('-ibotta') + assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) + else + # this is asserting that > 4.9 "fails" without the patch + assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob))) + end + end +end + +if Resque::Scheduler::VERSION.end_with?('-ibotta') +class LockBatchOffTest < Minitest::Test + + def setup + @batch_enabled = Resque::Scheduler.enable_delayed_requeue_batches + @batch_size = Resque::Scheduler.delayed_requeue_batch_size + + $success = $lock_failed = $lock_expired = $enqueue_failed = 0 + Resque::Scheduler.quiet = true + Resque.redis.redis.flushall + @worker = Resque::Worker.new(:test) + + Resque::Scheduler.enable_delayed_requeue_batches = false + Resque::Scheduler.delayed_requeue_batch_size = 1 + end + + def teardown + Resque::Scheduler.enable_delayed_requeue_batches = @batch_enabled + Resque::Scheduler.delayed_requeue_batch_size = @batch_size + end + + def test_delayed_item_enqueue + t = Time.now + 60 + + # Resque::Scheduler.expects(:enqueue_next_item).never + + # create 90 jobs + 90.times { Resque.enqueue_at(t, LonelyJob) } + assert_equal(90, Resque.delayed_timestamp_size(t)) + + Resque::Scheduler.enqueue_delayed_items_for_timestamp(t) + assert_equal(0, Resque.delayed_timestamp_size(t)) + + # assert that the active queue has the lonely job + if scheduler_version_compare('< 4.9') + assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) + elsif Resque::Scheduler::VERSION.end_with?('-ibotta') + assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) else # this is asserting that > 4.9 "fails" without the patch assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob))) end end +end + +class LockBatchOnTest < Minitest::Test + + def setup + @batch_enabled = Resque::Scheduler.enable_delayed_requeue_batches + @batch_size = Resque::Scheduler.delayed_requeue_batch_size + + $success = $lock_failed = $lock_expired = $enqueue_failed = 0 + Resque::Scheduler.quiet = true + Resque.redis.redis.flushall + @worker = Resque::Worker.new(:test) + + Resque::Scheduler.enable_delayed_requeue_batches = true + Resque::Scheduler.delayed_requeue_batch_size = 100 + end + + def teardown + Resque::Scheduler.enable_delayed_requeue_batches = @batch_enabled + Resque::Scheduler.delayed_requeue_batch_size = @batch_size + end + + def test_delayed_item_enqueue + t = Time.now + 60 + + # Resque::Scheduler.expects(:enqueue_next_item).never + + # create 90 jobs + 90.times { Resque.enqueue_at(t, LonelyJob) } + assert_equal(90, Resque.delayed_timestamp_size(t)) + + Resque::Scheduler.enqueue_delayed_items_for_timestamp(t) + assert_equal(0, Resque.delayed_timestamp_size(t)) + + # assert that the active queue has the lonely job + if scheduler_version_compare('< 4.9') + assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) + elsif Resque::Scheduler::VERSION.end_with?('-ibotta') + assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob))) + else + # this is asserting that > 4.9 "fails" without the patch + assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob))) + end + end +end end From a057b0cc51b80413c647f84df0f8635eecdd0f8c Mon Sep 17 00:00:00 2001 From: Justin Hart Date: Wed, 16 Oct 2024 12:23:21 -0700 Subject: [PATCH 5/7] debug --- .gitignore | 1 + resque-lock-timeout.gemspec | 1 + test/integration/resque-scheduler/delayed_job_test.rb | 3 +++ 3 files changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index abc9a7d..46ff542 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ coverage/ .bundle/ dump.rdb stdout +.vscode diff --git a/resque-lock-timeout.gemspec b/resque-lock-timeout.gemspec index ab8f6a5..e921859 100644 --- a/resque-lock-timeout.gemspec +++ b/resque-lock-timeout.gemspec @@ -19,6 +19,7 @@ Gem::Specification.new do |s| s.add_development_dependency("minitest") s.add_development_dependency("yard") s.add_development_dependency("simplecov") + s.add_development_dependency("debug") s.description = <<-DESC A Resque plugin. Adds locking, with optional timeout/deadlock handling to diff --git a/test/integration/resque-scheduler/delayed_job_test.rb b/test/integration/resque-scheduler/delayed_job_test.rb index 32dad92..f6f3c20 100644 --- a/test/integration/resque-scheduler/delayed_job_test.rb +++ b/test/integration/resque-scheduler/delayed_job_test.rb @@ -1,5 +1,7 @@ require File.dirname(__FILE__) + "/../../test_helper" +require "debug" + require 'resque-scheduler' def scheduler_version_compare(version) @@ -75,6 +77,7 @@ def test_delayed_item_enqueue if scheduler_version_compare('< 4.9') assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) elsif Resque::Scheduler::VERSION.end_with?('-ibotta') + # should act like before assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) else # this is asserting that > 4.9 "fails" without the patch From 66c31f4605d67b8154bd031308c8c47e9e35943e Mon Sep 17 00:00:00 2001 From: Justin Hart Date: Wed, 16 Oct 2024 13:36:53 -0700 Subject: [PATCH 6/7] move integration test out --- .github/workflows/ci.yml | 12 -- Gemfile | 15 -- Rakefile | 6 - .../resque-scheduler/delayed_job_test.rb | 133 ------------------ 4 files changed, 166 deletions(-) delete mode 100644 test/integration/resque-scheduler/delayed_job_test.rb diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 260ea1e..fc0ec5f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,19 +32,9 @@ jobs: redis-version: - "~> 3.3" - "~> 4.8" - resque-scheduler-version: - - "4.3.0" - - "< 4.9.0" - - "~> 4.9" - - "https://github.com/Ibotta/resque-scheduler.git@enqueue-multi-rollback" - exclude: - # resque-scheduler (= 4.3.0) depends on redis (~> 3.3) - - redis-version: "~> 4.8" - resque-scheduler-version: "4.3.0" env: REDIS_VERSION: "${{ matrix.redis-version }}" RESQUE: "${{ matrix.resque-version }}" - RESQUE_SCHEDULER_VERSION: "${{ matrix.resque-scheduler-version }}" # The hostname used to communicate with the Redis service container REDIS_TEST_HOST: localhost # The default Redis port @@ -58,6 +48,4 @@ jobs: bundler-cache: true - name: Run tests run: bundle exec rake - - name: Run integration tests - run: bundle exec rake test_integration diff --git a/Gemfile b/Gemfile index 6e6648e..1239d56 100644 --- a/Gemfile +++ b/Gemfile @@ -24,19 +24,4 @@ else gem 'redis', *versions end -case resque_scheduler_version = ENV.fetch('RESQUE_SCHEDULER_VERSION', 'none') -when 'master' - gem 'resque-scheduler', git: 'https://github.com/resque/resque-scheduler' -when /^git:/, /^https:/ - repo, ref = resque_scheduler_version.split('@', 2) - gem 'resque-scheduler', git: repo, ref: ref -when 'latest' - gem 'resque-scheduler' -when 'none' - #noop -else - versions = resque_scheduler_version.split(',') - gem 'resque-scheduler', *versions -end - gemspec diff --git a/Rakefile b/Rakefile index 51dbfc1..4ae1bf4 100644 --- a/Rakefile +++ b/Rakefile @@ -10,12 +10,6 @@ Rake::TestTask.new(:test) do |task| task.verbose = true end -desc "Run resque-scheduler integration tests." -Rake::TestTask.new(:test_integration) do |task| - task.test_files = FileList["test/integration/**/*_test.rb"] - task.verbose = true -end - desc "Build Yardoc documentation." YARD::Rake::YardocTask.new :yardoc do |t| t.files = ["lib/**/*.rb"] diff --git a/test/integration/resque-scheduler/delayed_job_test.rb b/test/integration/resque-scheduler/delayed_job_test.rb deleted file mode 100644 index f6f3c20..0000000 --- a/test/integration/resque-scheduler/delayed_job_test.rb +++ /dev/null @@ -1,133 +0,0 @@ -require File.dirname(__FILE__) + "/../../test_helper" - -require "debug" - -require 'resque-scheduler' - -def scheduler_version_compare(version) - Gem::Requirement.create(version).satisfied_by?(Gem::Version.create(Resque::Scheduler::VERSION)) -end - -class LockTest < Minitest::Test - def setup - $success = $lock_failed = $lock_expired = $enqueue_failed = 0 - Resque::Scheduler.quiet = true - Resque.redis.redis.flushall - @worker = Resque::Worker.new(:test) - end - - def test_delayed_item_enqueue - t = Time.now + 60 - - # Resque::Scheduler.expects(:enqueue_next_item).never - - # create 90 jobs - 90.times { Resque.enqueue_at(t, LonelyJob) } - assert_equal(90, Resque.delayed_timestamp_size(t)) - - Resque::Scheduler.enqueue_delayed_items_for_timestamp(t) - assert_equal(0, Resque.delayed_timestamp_size(t)) - - # assert that the active queue has the lonely job - if scheduler_version_compare('< 4.9') - assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) - elsif Resque::Scheduler::VERSION.end_with?('-ibotta') - assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) - else - # this is asserting that > 4.9 "fails" without the patch - assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob))) - end - end -end - -if Resque::Scheduler::VERSION.end_with?('-ibotta') -class LockBatchOffTest < Minitest::Test - - def setup - @batch_enabled = Resque::Scheduler.enable_delayed_requeue_batches - @batch_size = Resque::Scheduler.delayed_requeue_batch_size - - $success = $lock_failed = $lock_expired = $enqueue_failed = 0 - Resque::Scheduler.quiet = true - Resque.redis.redis.flushall - @worker = Resque::Worker.new(:test) - - Resque::Scheduler.enable_delayed_requeue_batches = false - Resque::Scheduler.delayed_requeue_batch_size = 1 - end - - def teardown - Resque::Scheduler.enable_delayed_requeue_batches = @batch_enabled - Resque::Scheduler.delayed_requeue_batch_size = @batch_size - end - - def test_delayed_item_enqueue - t = Time.now + 60 - - # Resque::Scheduler.expects(:enqueue_next_item).never - - # create 90 jobs - 90.times { Resque.enqueue_at(t, LonelyJob) } - assert_equal(90, Resque.delayed_timestamp_size(t)) - - Resque::Scheduler.enqueue_delayed_items_for_timestamp(t) - assert_equal(0, Resque.delayed_timestamp_size(t)) - - # assert that the active queue has the lonely job - if scheduler_version_compare('< 4.9') - assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) - elsif Resque::Scheduler::VERSION.end_with?('-ibotta') - # should act like before - assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) - else - # this is asserting that > 4.9 "fails" without the patch - assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob))) - end - end -end - -class LockBatchOnTest < Minitest::Test - - def setup - @batch_enabled = Resque::Scheduler.enable_delayed_requeue_batches - @batch_size = Resque::Scheduler.delayed_requeue_batch_size - - $success = $lock_failed = $lock_expired = $enqueue_failed = 0 - Resque::Scheduler.quiet = true - Resque.redis.redis.flushall - @worker = Resque::Worker.new(:test) - - Resque::Scheduler.enable_delayed_requeue_batches = true - Resque::Scheduler.delayed_requeue_batch_size = 100 - end - - def teardown - Resque::Scheduler.enable_delayed_requeue_batches = @batch_enabled - Resque::Scheduler.delayed_requeue_batch_size = @batch_size - end - - def test_delayed_item_enqueue - t = Time.now + 60 - - # Resque::Scheduler.expects(:enqueue_next_item).never - - # create 90 jobs - 90.times { Resque.enqueue_at(t, LonelyJob) } - assert_equal(90, Resque.delayed_timestamp_size(t)) - - Resque::Scheduler.enqueue_delayed_items_for_timestamp(t) - assert_equal(0, Resque.delayed_timestamp_size(t)) - - # assert that the active queue has the lonely job - if scheduler_version_compare('< 4.9') - assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob))) - elsif Resque::Scheduler::VERSION.end_with?('-ibotta') - assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob))) - else - # this is asserting that > 4.9 "fails" without the patch - assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob))) - end - end -end - -end From 317fb1a829a8a2d0cc556ba27dfa412017b692d4 Mon Sep 17 00:00:00 2001 From: Justin Hart Date: Thu, 31 Oct 2024 14:11:59 -0700 Subject: [PATCH 7/7] update readme, gem name --- README.md | 17 +++++++++++------ resque-lock-timeout.gemspec | 4 ++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7c1775c..070d352 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # Resque Lock Timeout -A [Resque][rq] plugin. Requires Resque ~> 1.23. +A [Resque][rq] plugin. Requires Resque ~> 1.23, redis-rb >= 3.3, < 5. + +This is a fork of [resque-lock-timeout][resque-lock-timeout] with testing and other fixes applied. + +---------- resque-lock-timeout adds locking, with optional timeout/deadlock handling to resque jobs. @@ -56,7 +60,7 @@ end The locking algorithm used can be found in the [Redis SETNX][redis-setnx] documentation. -Simply set the lock timeout in seconds, e.g. +Set the lock timeout in seconds, e.g. ```ruby class UpdateNetworkGraph @@ -76,9 +80,9 @@ end ### Job Identifier/Lock Key -By default the key uses this format: `lock::`. +By default, the key uses this format: `lock::`. -The default identifier is just your job arguments joined with a dash `-`. +The default identifier is your job arguments joined with a dash `-`. If you have a lot of arguments or really long ones, you should consider overriding `identifier` to define a more precise or loose custom identifier: @@ -123,7 +127,7 @@ That would use the key `lock:updates`. ### Redis Connection Used for Locking -By default all locks are stored via Resque's redis connection. If you wish to change this you may override `lock_redis`. +By default, all locks are stored via Resque's redis connection. If you wish to change this you may override `lock_redis`. ```ruby class UpdateNetworkGraph @@ -165,7 +169,7 @@ end - `enqueued?` - checks if the loner lock is currently held. - `loner_locked?` - checks if the job is either enqueued (if a loner) or locked (any job). - `refresh_lock!` - Refresh the lock, useful for jobs that are taking longer - then usual but your okay with them holding on to the lock a little longer. + then usual but you're okay with them holding on to the lock a little longer. ### Callbacks @@ -221,3 +225,4 @@ Forked from [a little tinkering from Luke Antins](https://github.com/lantins/res [redis-setnx]: http://redis.io/commands/setnx [resque-lock]: http://github.com/defunkt/resque-lock [resque-lock-retry]: http://github.com/rcarver/resque-lock-retry +[resque-lock-timeout]: https://github.com/lantins/resque-lock-timeout diff --git a/resque-lock-timeout.gemspec b/resque-lock-timeout.gemspec index e921859..5d50089 100644 --- a/resque-lock-timeout.gemspec +++ b/resque-lock-timeout.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| - s.name = "resque-lock-timeout" - s.version = "0.5.0" + s.name = "ibotta-resque-lock-timeout" + s.version = "0.5.1" s.date = Time.now.strftime("%Y-%m-%d") s.summary = "A Resque plugin adding locking, with optional timeout/deadlock handling to resque jobs." s.license = "MIT"