Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
os: [ubuntu-latest]
ruby: [
2.7
3.4
]

steps:
Expand Down
47 changes: 7 additions & 40 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,62 +19,29 @@ jobs:
fail-fast: false
matrix:
ruby-version:
- 2.3
- 2.4
- 2.5
- 2.6
- 2.7
- "3.0"
- 3.1
- 3.2
- 3.3
- 3.4
- head
resque-version:
- "master"
- "~> 2.4.0"
- "~> 1.27"
rufus-scheduler:
- "3.2"
- "3.4"
- "3.5"
- "3.6"
redis-version:
- "~> 4.x"
- "~> 5.x"
exclude:
- ruby-version: head
rufus-scheduler: 3.2
- ruby-version: 3.2
rufus-scheduler: 3.2
- ruby-version: 3.3
rufus-scheduler: 3.2
- ruby-version: 3.4
rufus-scheduler: 3.2

- ruby-version: 2.3
resque-version: "~> 1.27"
rufus-scheduler: 3.4
- ruby-version: 2.3
resque-version: "~> 1.27"
rufus-scheduler: 3.5
- ruby-version: 2.5
resque-version: "~> 2.4.0"
rufus-scheduler: 3.5
- ruby-version: 2.5
resque-version: master
rufus-scheduler: 3.2

- ruby-version: 2.3
redis-version: "~> 5.x"
- ruby-version: 2.4
redis-version: "~> 5.x"

- resque-version: "~> 1.27"
redis-version: "~> 5.x"
- "4.8"
- "latest"
rack-version:
- 2
- 3
env:
REDIS_VERSION: "${{ matrix.redis-version }}"
RESQUE: "${{ matrix.resque-version }}"
RUFUS_SCHEDULER: "${{ matrix.rufus-scheduler }}"
RACK_VERSION: "${{ matrix.rack-version }}"
COVERAGE: 1

steps:
Expand Down
29 changes: 22 additions & 7 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
inherit_from: .rubocop_todo.yml

AllCops:
Include:
- Gemfile
- '**/Rakefile'
- resque-scheduler.gemspec
- bin/resque-scheduler
TargetRubyVersion: 3.0
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: true
Exclude:
- 'log/**/*'
- 'vendor/**/*'
- 'examples/**/*'

Layout/IndentationStyle:
Enabled: true

Layout/TrailingEmptyLines:
Enabled: true

Layout/TrailingWhitespace:
Enabled: true

Metrics/ClassLength:
Enabled: true
Max: 110

Documentation:
Enabled: false

Style/DoubleNegation:
Enabled: false

Metrics/PerceivedComplexity:
Enabled: false
Metrics/ClassLength:
Max: 110
1 change: 1 addition & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Style/FileName:
Style/GuardClause:
Exclude:
- 'lib/resque/scheduler/lock/basic.rb'
- 'lib/resque/scheduler.rb'

# Offense count: 1
Style/IfInsideElse:
Expand Down
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ else
gem 'redis', redis_version
end

rack_version = ENV.fetch('RACK_VERSION', '3')
gem 'rack', "~> #{rack_version}.0"

if rack_version.to_i >= 3
gem 'rackup'
end

gem 'sinatra', '> 2.0'

gemspec
4 changes: 3 additions & 1 deletion lib/resque/scheduler/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ def delayed
def delayed_jobs_klass
begin
klass = Resque::Scheduler::Util.constantize(params[:klass])
@args = JSON.load(CGI.unescape(params[:args]))
args_param = params[:args] || params['args']
@args = args_param ? JSON.parse(URI.decode_www_form_component(args_param)) : []
@timestamps = Resque.scheduled_at(klass, *@args)
rescue
@args = []
@timestamps = []
end

Expand Down
2 changes: 1 addition & 1 deletion lib/resque/scheduler/server/views/delayed_schedules.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<% @timestamps.each do |t| %>
<tr>
<td>
<%= Time.at(t) %>
<%= format_time(Time.at(t)) %>
</td>
</tr>
<% end %>
Expand Down
11 changes: 6 additions & 5 deletions resque-scheduler.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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 = '>= 3.0.0'

spec.files = `git ls-files -z`.split("\0").reject do |f|
f.match(%r{^(test|spec|features|examples|bin|tasks)/}) ||
Expand All @@ -45,11 +45,11 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'json'
spec.add_development_dependency 'irb'
spec.add_development_dependency 'minitest'
spec.add_development_dependency 'mocha'
spec.add_development_dependency 'ostruct'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'rack', '< 3'
spec.add_development_dependency 'rack-test'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'simplecov'
Expand All @@ -59,12 +59,13 @@ Gem::Specification.new do |spec|

# 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 'rubocop', '~> 0.80'

spec.add_runtime_dependency 'base64', '~> 0.1'
spec.add_runtime_dependency 'logger'
spec.add_runtime_dependency 'mono_logger', '~> 1.0'
spec.add_runtime_dependency 'redis', '>= 3.3'
spec.add_runtime_dependency 'resque', '>= 1.27'
spec.add_runtime_dependency 'redis', '>= 4.0'
spec.add_runtime_dependency 'resque', '>= 3.0'
# rufus-scheduler v3.7 causes a failure in test/multi_process_test.rb
# rufus-scheduler v3.3 is missing a to_local method which fails tests
spec.add_runtime_dependency 'rufus-scheduler', '~> 3.2', '!= 3.3'
Expand Down
12 changes: 8 additions & 4 deletions test/resque-web_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@
test('is 200') { assert last_response.ok? }

test 'see the scheduled job' do
assert last_response.body.include?(@t.to_s)
formatted_time = @t.strftime('%Y-%m-%d %H:%M:%S %z')
assert last_response.body.include?(formatted_time),
"Expected response to include timestamp #{formatted_time}"
end

context 'with a namespaced class' do
Expand All @@ -142,7 +144,9 @@ def self.queue
test('is 200') { assert last_response.ok? }

test 'see the scheduled job' do
assert last_response.body.include?(@t.to_s)
formatted_time = @t.strftime('%Y-%m-%d %H:%M:%S %z')
assert last_response.body.include?(formatted_time),
"Expected response to include timestamp #{formatted_time}"
end
end
end
Expand Down Expand Up @@ -187,7 +191,7 @@ module Test

post '/schedule/requeue', 'job_name' => job_name
follow_redirect!
assert_equal 'http://example.org/overview', last_request.url
assert_equal 'http://localhost/overview', last_request.url
assert last_response.ok?
end

Expand Down Expand Up @@ -237,7 +241,7 @@ module Test
'log_level' => log_level

follow_redirect!
assert_equal 'http://example.org/overview', last_request.url
assert_equal 'http://localhost/overview', last_request.url

assert last_response.ok?, last_response.errors
end
Expand Down
20 changes: 10 additions & 10 deletions test/scheduler_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
test 'sending TERM to scheduler breaks out of poll_sleep' do
Resque::Scheduler.expects(:release_master_lock)

@pid = Process.pid
pid = Process.pid
Thread.new do
sleep(0.05)
Process.kill(:TERM, @pid)
Process.kill(:TERM, pid)
end

assert_raises SystemExit do
Expand All @@ -41,10 +41,10 @@
test 'can start successfully' do
Resque::Scheduler.poll_sleep_amount = nil

@pid = Process.pid
pid = Process.pid
Thread.new do
sleep(0.15)
Process.kill(:TERM, @pid)
Process.kill(:TERM, pid)
end

assert_raises SystemExit do
Expand All @@ -56,10 +56,10 @@
Resque::Scheduler.poll_sleep_amount = 0
Resque::Scheduler.expects(:release_master_lock)

@pid = Process.pid
pid = Process.pid
Thread.new do
sleep(0.05)
Process.kill(:TERM, @pid)
Process.kill(:TERM, pid)
end

assert_raises SystemExit do
Expand All @@ -86,10 +86,10 @@
test 'logs scheduler master' do
Resque::Scheduler.expects(:master?).returns(true)

@pid = Process.pid
pid = Process.pid
Thread.new do
sleep(0.1)
Process.kill(:TERM, @pid)
Process.kill(:TERM, pid)
end

assert_raises SystemExit do
Expand All @@ -102,10 +102,10 @@
test 'logs scheduler child' do
Resque::Scheduler.expects(:master?).returns(false)

@pid = Process.pid
pid = Process.pid
Thread.new do
sleep(0.1)
Process.kill(:TERM, @pid)
Process.kill(:TERM, pid)
end

assert_raises SystemExit do
Expand Down
5 changes: 5 additions & 0 deletions test/server/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ module Resque
module TestHelper
class Test::Unit::TestCase # rubocop:disable Style/ClassAndModuleChildren
include Rack::Test::Methods

def app
Resque::Server.new
end

def default_host
'localhost'
end

def self.should_respond_with_success
test 'should respond with success' do
assert last_response.ok?, last_response.errors
Expand Down