diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml index 4836bf71..466b33f8 100644 --- a/.github/workflows/rubocop.yml +++ b/.github/workflows/rubocop.yml @@ -6,16 +6,22 @@ on: pull_request: branches: [master] +# This allows a subsequently queued workflow run to interrupt previous runs +concurrency: + group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' + cancel-in-progress: true + jobs: rubocop: name: Rubocop - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest strategy: matrix: - os: [ubuntu-latest] - ruby: [ - 2.7 - ] + ruby: + - "3.0" + - "3.1" + - "3.2" + - "3.3" steps: - uses: actions/checkout@v4 diff --git a/.rubocop.yml b/.rubocop.yml index d7063c9f..54281c72 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,18 +1,20 @@ -inherit_from: .rubocop_todo.yml - AllCops: + TargetRubyVersion: 2.7 + NewCops: enable Include: - Gemfile - '**/Rakefile' - resque-scheduler.gemspec - bin/resque-scheduler -Documentation: - Enabled: false - Style/DoubleNegation: Enabled: false Metrics/PerceivedComplexity: Enabled: false Metrics/ClassLength: Max: 110 +Bundler/DuplicatedGem: + Exclude: + - 'Gemfile' +Style/FrozenStringLiteralComment: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index 97902050..00000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,71 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2016-06-26 12:36:38 -0400 using RuboCop version 0.40.0. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 1 -# Configuration parameters: AllowSafeAssignment. -Lint/AssignmentInCondition: - Exclude: - - 'lib/resque/scheduler/env.rb' - -# Offense count: 2 -Lint/UselessAccessModifier: - Exclude: - - 'lib/resque/scheduler.rb' - -# Offense count: 17 -Metrics/AbcSize: - Max: 36 - -# Offense count: 3 -Metrics/CyclomaticComplexity: - Max: 12 - -# Offense count: 6 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes. -# URISchemes: http, https -Metrics/LineLength: - Max: 96 - -# Offense count: 20 -# Configuration parameters: CountComments. -Metrics/MethodLength: - Max: 34 - -# Offense count: 2 -# Configuration parameters: CountComments. -Metrics/ModuleLength: - Max: 364 - -# Offense count: 1 -Style/CaseEquality: - Exclude: - - 'lib/resque/scheduler.rb' - -# Offense count: 1 -Style/EachWithObject: - Exclude: - - 'lib/resque/scheduler.rb' - -# Offense count: 3 -# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts. -Style/FileName: - Exclude: - - 'examples/config/initializers/resque-web.rb' - - 'lib/resque-scheduler.rb' - - 'test/resque-web_test.rb' - -# Offense count: 1 -# Configuration parameters: MinBodyLength. -Style/GuardClause: - Exclude: - - 'lib/resque/scheduler/lock/basic.rb' - -# Offense count: 1 -Style/IfInsideElse: - Exclude: - - 'lib/resque/scheduler.rb' diff --git a/Gemfile b/Gemfile index 38ce455a..1e834102 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 source 'https://rubygems.org' case resque_version = ENV.fetch('RESQUE', 'latest') diff --git a/Rakefile b/Rakefile index 763604e0..cd3a078b 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require 'bundler/gem_tasks' require 'rake/testtask' require 'yard' diff --git a/bin/migrate_to_timestamps_set.rb b/bin/migrate_to_timestamps_set.rb index 915242f0..c2aedc25 100644 --- a/bin/migrate_to_timestamps_set.rb +++ b/bin/migrate_to_timestamps_set.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - require 'redis' require 'resque' diff --git a/examples/Rakefile b/examples/Rakefile index bf31d618..9160bbb7 100644 --- a/examples/Rakefile +++ b/examples/Rakefile @@ -1,2 +1 @@ -# vim:fileencoding=utf-8 require 'resque/scheduler/tasks' diff --git a/examples/config/initializers/resque-web.rb b/examples/config/initializers/resque-web.rb index 4c12eb9d..58271949 100644 --- a/examples/config/initializers/resque-web.rb +++ b/examples/config/initializers/resque-web.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - require 'json' require 'yaml' require 'resque' diff --git a/examples/dynamic-scheduling/app/jobs/fix_schedules_job.rb b/examples/dynamic-scheduling/app/jobs/fix_schedules_job.rb index 719914ae..53bdb486 100644 --- a/examples/dynamic-scheduling/app/jobs/fix_schedules_job.rb +++ b/examples/dynamic-scheduling/app/jobs/fix_schedules_job.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 # # Background job to fix the schedule for email sending. Any missing # schedule will be added to resque-schedule. diff --git a/examples/dynamic-scheduling/app/jobs/send_email_job.rb b/examples/dynamic-scheduling/app/jobs/send_email_job.rb index 6a9473fa..42da692f 100644 --- a/examples/dynamic-scheduling/app/jobs/send_email_job.rb +++ b/examples/dynamic-scheduling/app/jobs/send_email_job.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - class SendEmailJob @queue = :send_emails diff --git a/examples/dynamic-scheduling/app/models/user.rb b/examples/dynamic-scheduling/app/models/user.rb index 5f043e83..88343be5 100644 --- a/examples/dynamic-scheduling/app/models/user.rb +++ b/examples/dynamic-scheduling/app/models/user.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - class User < ActiveRecord::Base after_create :schedule_send_email diff --git a/examples/dynamic-scheduling/lib/tasks/resque.rake b/examples/dynamic-scheduling/lib/tasks/resque.rake index 5e7e8a07..6bcc675f 100644 --- a/examples/dynamic-scheduling/lib/tasks/resque.rake +++ b/examples/dynamic-scheduling/lib/tasks/resque.rake @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - require 'resque/tasks' require 'resque/scheduler/tasks' require 'yaml' diff --git a/exe/resque-scheduler b/exe/resque-scheduler index f26121d1..2c34d5e8 100755 --- a/exe/resque-scheduler +++ b/exe/resque-scheduler @@ -1,5 +1,4 @@ #!/usr/bin/env ruby -# vim:fileencoding=utf-8 require 'resque-scheduler' Resque::Scheduler::Cli.run! diff --git a/lib/resque-scheduler.rb b/lib/resque-scheduler.rb index b770cd91..8d19f7c7 100644 --- a/lib/resque-scheduler.rb +++ b/lib/resque-scheduler.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require_relative 'resque/scheduler' Resque.extend Resque::Scheduler::Extension diff --git a/lib/resque/scheduler.rb b/lib/resque/scheduler.rb index 8bea6cf1..ed5edb29 100644 --- a/lib/resque/scheduler.rb +++ b/lib/resque/scheduler.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - require 'redis/errors' require 'rufus/scheduler' require_relative 'scheduler/configuration' diff --git a/lib/resque/scheduler/cli.rb b/lib/resque/scheduler/cli.rb index c0d7fea9..1cc616ff 100644 --- a/lib/resque/scheduler/cli.rb +++ b/lib/resque/scheduler/cli.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - require 'optparse' module Resque diff --git a/lib/resque/scheduler/configuration.rb b/lib/resque/scheduler/configuration.rb index 5ecab2d9..e9fb9f22 100644 --- a/lib/resque/scheduler/configuration.rb +++ b/lib/resque/scheduler/configuration.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - module Resque module Scheduler module Configuration diff --git a/lib/resque/scheduler/delaying_extensions.rb b/lib/resque/scheduler/delaying_extensions.rb index 5a13cb41..355ad068 100644 --- a/lib/resque/scheduler/delaying_extensions.rb +++ b/lib/resque/scheduler/delaying_extensions.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require 'resque' require_relative 'plugin' require_relative '../scheduler' diff --git a/lib/resque/scheduler/env.rb b/lib/resque/scheduler/env.rb index 150e22a2..5c6393dc 100644 --- a/lib/resque/scheduler/env.rb +++ b/lib/resque/scheduler/env.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - require 'English' # $PROCESS_ID module Resque diff --git a/lib/resque/scheduler/extension.rb b/lib/resque/scheduler/extension.rb index f2728fa9..cd1aa3a8 100644 --- a/lib/resque/scheduler/extension.rb +++ b/lib/resque/scheduler/extension.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - require_relative 'scheduling_extensions' require_relative 'delaying_extensions' diff --git a/lib/resque/scheduler/lock.rb b/lib/resque/scheduler/lock.rb index ca7cbe48..c05f1785 100644 --- a/lib/resque/scheduler/lock.rb +++ b/lib/resque/scheduler/lock.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 %w(base basic resilient).each do |file| require "resque/scheduler/lock/#{file}" end diff --git a/lib/resque/scheduler/lock/base.rb b/lib/resque/scheduler/lock/base.rb index 164c2f9f..e32d01aa 100644 --- a/lib/resque/scheduler/lock/base.rb +++ b/lib/resque/scheduler/lock/base.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - module Resque module Scheduler module Lock diff --git a/lib/resque/scheduler/lock/basic.rb b/lib/resque/scheduler/lock/basic.rb index b2a030f1..8059d90d 100644 --- a/lib/resque/scheduler/lock/basic.rb +++ b/lib/resque/scheduler/lock/basic.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require_relative 'base' module Resque diff --git a/lib/resque/scheduler/lock/resilient.rb b/lib/resque/scheduler/lock/resilient.rb index 130eebf5..6bdedeed 100644 --- a/lib/resque/scheduler/lock/resilient.rb +++ b/lib/resque/scheduler/lock/resilient.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require_relative 'base' module Resque diff --git a/lib/resque/scheduler/locking.rb b/lib/resque/scheduler/locking.rb index a541edcc..1d26f3d0 100644 --- a/lib/resque/scheduler/locking.rb +++ b/lib/resque/scheduler/locking.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - # ### Locking the scheduler process # # There are two places in resque-scheduler that need to be synchronized in order diff --git a/lib/resque/scheduler/logger_builder.rb b/lib/resque/scheduler/logger_builder.rb index 0b8b605a..e7e37d23 100644 --- a/lib/resque/scheduler/logger_builder.rb +++ b/lib/resque/scheduler/logger_builder.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - require 'mono_logger' module Resque diff --git a/lib/resque/scheduler/plugin.rb b/lib/resque/scheduler/plugin.rb index bab898b4..71047ca1 100644 --- a/lib/resque/scheduler/plugin.rb +++ b/lib/resque/scheduler/plugin.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - module Resque module Scheduler module Plugin diff --git a/lib/resque/scheduler/scheduling_extensions.rb b/lib/resque/scheduler/scheduling_extensions.rb index 9cf569ad..22649dc7 100644 --- a/lib/resque/scheduler/scheduling_extensions.rb +++ b/lib/resque/scheduler/scheduling_extensions.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - module Resque module Scheduler module SchedulingExtensions diff --git a/lib/resque/scheduler/server.rb b/lib/resque/scheduler/server.rb index fa299654..f57630b8 100644 --- a/lib/resque/scheduler/server.rb +++ b/lib/resque/scheduler/server.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require 'resque-scheduler' require 'resque/server' require 'tilt/erb' diff --git a/lib/resque/scheduler/signal_handling.rb b/lib/resque/scheduler/signal_handling.rb index 43a400d7..cb70f1af 100644 --- a/lib/resque/scheduler/signal_handling.rb +++ b/lib/resque/scheduler/signal_handling.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - module Resque module Scheduler module SignalHandling diff --git a/lib/resque/scheduler/tasks.rb b/lib/resque/scheduler/tasks.rb index 7e5e88a9..8b6d2613 100644 --- a/lib/resque/scheduler/tasks.rb +++ b/lib/resque/scheduler/tasks.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - require 'resque/tasks' require 'resque-scheduler' diff --git a/lib/resque/scheduler/util.rb b/lib/resque/scheduler/util.rb index fc8df2b1..4b7c580b 100644 --- a/lib/resque/scheduler/util.rb +++ b/lib/resque/scheduler/util.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - module Resque module Scheduler class Util diff --git a/lib/resque/scheduler/version.rb b/lib/resque/scheduler/version.rb index 368e3f6c..13e5b36c 100644 --- a/lib/resque/scheduler/version.rb +++ b/lib/resque/scheduler/version.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - module Resque module Scheduler VERSION = '4.10.2'.freeze diff --git a/resque-scheduler.gemspec b/resque-scheduler.gemspec index 67b2583c..16f9ab3e 100644 --- a/resque-scheduler.gemspec +++ b/resque-scheduler.gemspec @@ -1,27 +1,26 @@ -# vim:fileencoding=utf-8 -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'resque/scheduler/version' Gem::Specification.new do |spec| spec.name = 'resque-scheduler' spec.version = Resque::Scheduler::VERSION - spec.authors = <<-EOF.split(/\n/).map(&:strip) + spec.authors = <<-AUTHORS.split(/\n/).map(&:strip) Ben VandenBos Simon Eskildsen Ryan Biesemeyer Dan Buch Michael Bianco Patrick Tulskie - EOF - spec.email = %w( + AUTHORS + spec.email = %w[ bvandenbos@gmail.com sirup@sirupsen.com ryan@yaauie.com dan@meatballhat.com mike@mikebian.co patricktulskie@gmail.com - ) + ] spec.summary = 'Light weight job scheduling on top of Resque' spec.description = <<-DESCRIPTION Light weight job scheduling on top of Resque. @@ -32,7 +31,7 @@ Gem::Specification.new do |spec| spec.license = 'MIT' spec.metadata['rubygems_mfa_required'] = 'true' - spec.required_ruby_version = '>= 2.3.0' + spec.required_ruby_version = '>= 2.7.0' spec.files = `git ls-files -z`.split("\0").reject do |f| f.match(%r{^(test|spec|features|examples|bin|tasks)/}) || @@ -41,7 +40,7 @@ Gem::Specification.new do |spec| end spec.bindir = 'exe' spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } - spec.require_paths = %w(lib) + spec.require_paths = %w[lib] spec.add_development_dependency 'bundler' spec.add_development_dependency 'json' @@ -52,12 +51,14 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rake' spec.add_development_dependency 'simplecov' spec.add_development_dependency 'test-unit' - spec.add_development_dependency 'yard' spec.add_development_dependency 'timecop' + spec.add_development_dependency 'yard' # We pin rubocop because new cops have a tendency to result in false-y # positives for new contributors, which is not a nice experience. - spec.add_development_dependency 'rubocop', '~> 0.40.0' + spec.add_development_dependency 'ostruct' + spec.add_development_dependency 'racc' + spec.add_development_dependency 'rubocop', '~> 0.92.0' spec.add_runtime_dependency 'mono_logger', '~> 1.0' spec.add_runtime_dependency 'redis', '>= 3.3' diff --git a/test/cli_test.rb b/test/cli_test.rb index 99e76d01..3f1ac132 100644 --- a/test/cli_test.rb +++ b/test/cli_test.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require_relative 'test_helper' context 'Cli' do diff --git a/test/configuration_test.rb b/test/configuration_test.rb index 2abed87f..5352e81f 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require_relative 'test_helper' context 'Configuration' do diff --git a/test/delayed_queue_test.rb b/test/delayed_queue_test.rb index 03d41038..c6500fa9 100644 --- a/test/delayed_queue_test.rb +++ b/test/delayed_queue_test.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require_relative 'test_helper' def assert_resque_key_exists?(key) @@ -391,7 +390,7 @@ def assert_resque_key_exists?(key) assert_equal(1, Resque.delayed_timestamp_peek(t, 0, 3).length) end - context "non-batch delayed item queue" do + context 'non-batch delayed item queue' do batch_enabled = Resque::Scheduler.enable_delayed_requeue_batches batch_size = Resque::Scheduler.delayed_requeue_batch_size setup do @@ -422,10 +421,36 @@ def assert_resque_key_exists?(key) assert_equal(90, Resque.size(Resque.queue_from_class(SomeIvarJob))) end - # TODO clean up timestamp? + # test to make sure the timestamp is cleaned up + + test 'enqueue_delayed_items_for_timestamp handles a watch failure' do + t = Time.now + 60 + + # create 100 jobs + 100.times { Resque.enqueue_at(t, SomeIvarJob) } + assert_equal(100, Resque.delayed_timestamp_size(t)) + + Resque.redis.stubs(:watch).returns(nil) + + Resque.expects(:clean_up_timestamp).never + + Resque::Scheduler.enqueue_delayed_items_for_timestamp(t) + end + + test 'enqueue_delayed_items_for_timestamp cleans up a timestamp' do + t = Time.now + 60 + + # create 100 jobs + 100.times { Resque.enqueue_at(t, SomeIvarJob) } + assert_equal(100, Resque.delayed_timestamp_size(t)) + + Resque.expects(:clean_up_timestamp).once + + Resque::Scheduler.enqueue_delayed_items_for_timestamp(t) + end end - context "batch delayed item queue" do + context 'batch delayed item queue' do batch_enabled = Resque::Scheduler.enable_delayed_requeue_batches batch_size = Resque::Scheduler.delayed_requeue_batch_size setup do @@ -499,7 +524,6 @@ def assert_resque_key_exists?(key) Resque::Scheduler.enqueue_delayed_items_for_timestamp(t) end - end test 'enqueue_delayed_items_for_timestamp creates jobs ' \ diff --git a/test/env_test.rb b/test/env_test.rb index a8f2e214..714c7578 100644 --- a/test/env_test.rb +++ b/test/env_test.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require_relative 'test_helper' require_relative '../lib/resque/scheduler/env' diff --git a/test/multi_process_test.rb b/test/multi_process_test.rb index e02c4399..6a527707 100644 --- a/test/multi_process_test.rb +++ b/test/multi_process_test.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require_relative 'test_helper' context 'Multi Process' do diff --git a/test/resque-web_test.rb b/test/resque-web_test.rb index b2839e2b..abcb39ec 100644 --- a/test/resque-web_test.rb +++ b/test/resque-web_test.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require_relative 'test_helper' require_relative 'server/test_helper' diff --git a/test/scheduler_args_test.rb b/test/scheduler_args_test.rb index 7a0a7cd8..470f3e73 100644 --- a/test/scheduler_args_test.rb +++ b/test/scheduler_args_test.rb @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - require_relative 'test_helper' context 'scheduling jobs with arguments' do diff --git a/test/scheduler_hooks_test.rb b/test/scheduler_hooks_test.rb index 1128384e..155474a9 100644 --- a/test/scheduler_hooks_test.rb +++ b/test/scheduler_hooks_test.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require_relative 'test_helper' context 'scheduling jobs with hooks' do diff --git a/test/scheduler_locking_test.rb b/test/scheduler_locking_test.rb index aff8d70e..1305e971 100644 --- a/test/scheduler_locking_test.rb +++ b/test/scheduler_locking_test.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require_relative 'test_helper' module LockTestHelper diff --git a/test/scheduler_setup_test.rb b/test/scheduler_setup_test.rb index 34cff8f5..faeb31a3 100644 --- a/test/scheduler_setup_test.rb +++ b/test/scheduler_setup_test.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require_relative 'test_helper' context 'Resque::Scheduler' do diff --git a/test/scheduler_task_test.rb b/test/scheduler_task_test.rb index d409945b..17f9519a 100644 --- a/test/scheduler_task_test.rb +++ b/test/scheduler_task_test.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require_relative 'test_helper' context 'Resque::Scheduler' do diff --git a/test/scheduler_test.rb b/test/scheduler_test.rb index d7a4208d..3f6546c2 100644 --- a/test/scheduler_test.rb +++ b/test/scheduler_test.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require_relative 'test_helper' require 'ostruct' diff --git a/test/util_test.rb b/test/util_test.rb index 0a58fe7e..98004367 100644 --- a/test/util_test.rb +++ b/test/util_test.rb @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 require_relative 'test_helper' context 'Util' do