Skip to content

Commit

Permalink
Add support for Rails 7 (alpha2) (#3)
Browse files Browse the repository at this point in the history
This:
- Adds an `Appraisal` entry for `7.0.0.alpha2`. (I had to specify multiple gems to get the pre-release dependencies to resolve properly.)
- Bumps `.ruby-version` to `2.7`, but keeps linting at `2.6`. (CI will still run against all of 2.6-3.0)
- Fixes a deprecation warning about `ActiveRecord::Base.default_timezone` (switches to `ActiveRecord.default_timezone`)
- Fixes some YML-autoloading tests by enabling Zeitwerk in the 7.0 test suite. (The `:classic` autoloader is no longer used/supported in Rails 7)
- Autocorrects some new linter rules pulled from the latest version of the linter gem
- Bumps the version to 0.3.0 and updates the CHANGELOG
  • Loading branch information
smudge authored Oct 26, 2021
1 parent d82f789 commit 2d296b9
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ jobs:
- gemfiles/rails_5_2.gemfile
- gemfiles/rails_6_0.gemfile
- gemfiles/rails_6_1.gemfile
- gemfiles/rails_7_0.gemfile
exclude:
- ruby: 3.0
gemfile: gemfiles/rails_5_2.gemfile
- ruby: 2.6
gemfile: gemfiles/rails_7_0.gemfile
services:
postgres:
image: postgres
Expand Down
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ inherit_mode:
- Exclude

AllCops:
TargetRubyVersion: 2.6
Exclude:
- 'lib/generators/delayed/templates/*.rb'
NewCops: enable
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.5
2.7.4
6 changes: 6 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ end
appraise 'rails-6-1' do
gem 'activerecord', '~> 6.1.0'
end

appraise 'rails-7-0' do
gem 'actionmailer', '~> 7.0.0.alpha2'
gem 'activejob', '~> 7.0.0.alpha2'
gem 'activerecord', '~> 7.0.0.alpha2'
end
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ and this project aims to adhere to [Semantic Versioning](http://semver.org/spec/
### Removed <!-- for now removed features. -->
### Fixed <!-- for any bug fixes. -->

## [0.3.0] - 2021-10-26
### Added
- Add more official support for Rails 7.0 (currently alpha2). There were no gem conflicts, but this
adds an entry to our `Appraisals` file so that we run CI tests against ActiveRecord 7.
### Fixed
- Fix Rails 7.0 deprecation warnings caused by usages of `ActiveRecord::Base.default_timestamp`
- Fix tests that relied on classic autoloader behavior. Now we pull in Zeitwerk where necessary.
- Fix a couple issues caught by the linter, most notably resulting in a switch from `IO.select(...)`
to `IO#wait_readable(...)`, improving support for Ruby 3 scheduler hooks.

## [0.2.0] - 2021-08-30
### Fixed
- Fix the loading of `Delayed::Job` constant on newly-generated Rails 6.1 apps. (previously, the
Expand All @@ -33,6 +43,7 @@ and this project aims to adhere to [Semantic Versioning](http://semver.org/spec/
ancestor repos (`delayed_job` and `delayed_job_active_record`), plus the changes from Betterment's
internal forks.

[0.3.0]: https://github.com/betterment/delayed/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/betterment/delayed/compare/v0.1.1...v0.2.0
[0.1.1]: https://github.com/betterment/delayed/compare/v0.1.0...v0.1.1
[0.1.0]: https://github.com/betterment/delayed/releases/tag/v0.1.0
8 changes: 7 additions & 1 deletion app/models/delayed/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,19 @@ def self.reserve_with_scope_using_optimized_mssql(ready_scope, worker, now)
def self.db_time_now
if Time.zone
Time.zone.now
elsif ::ActiveRecord::Base.default_timezone == :utc
elsif default_timezone == :utc
Time.now.utc
else
Time.current
end
end

if ActiveRecord::VERSION::MAJOR >= 7
def self.default_timezone
ActiveRecord.default_timezone
end
end

def self.worker_tags(worker)
{
min_priority: worker.min_priority,
Expand Down
3 changes: 2 additions & 1 deletion delayed.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']
spec.summary = 'a multi-threaded, SQL-driven ActiveJob backend used at Betterment to process millions of background jobs per day'

spec.version = '0.2.0'
spec.version = '0.3.0'
spec.metadata = {
'changelog_uri' => 'https://github.com/betterment/delayed/blob/main/CHANGELOG.md',
'bug_tracker_uri' => 'https://github.com/betterment/delayed/issues',
Expand All @@ -40,4 +40,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'sqlite3'
spec.add_development_dependency 'timecop'
spec.add_development_dependency 'zeitwerk'
end
9 changes: 9 additions & 0 deletions gemfiles/rails_7_0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "actionmailer", "~> 7.0.0.alpha2"
gem "activejob", "~> 7.0.0.alpha2"
gem "activerecord", "~> 7.0.0.alpha2"

gemspec path: "../"
2 changes: 1 addition & 1 deletion lib/delayed/priority.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def <=>(other)
private

def respond_to_missing?(method_name, include_private = false)
method_name.to_s.end_with?('?') && self.class.names.key?(method_name.to_s[0..-2].to_sym) || super
(method_name.to_s.end_with?('?') && self.class.names.key?(method_name.to_s[0..-2].to_sym)) || super
end

def method_missing(method_name, *args)
Expand Down
2 changes: 1 addition & 1 deletion lib/delayed/runnable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def start
def on_exit!; end

def interruptable_sleep(seconds)
IO.select([pipe[0]], nil, nil, seconds)
pipe[0].wait_readable(seconds)
end

def stop
Expand Down
12 changes: 9 additions & 3 deletions spec/delayed/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,16 @@ def create_job(opts = {})
end
end

if ActiveRecord::VERSION::MAJOR >= 7
delegate :default_timezone=, to: ActiveRecord
else
delegate :default_timezone=, to: ActiveRecord::Base
end

context "db_time_now" do
after do
Time.zone = nil
ActiveRecord::Base.default_timezone = :local
self.default_timezone = :local
end

it "returns time in current time zone if set" do
Expand All @@ -752,13 +758,13 @@ def create_job(opts = {})

it "returns UTC time if that is the AR default" do
Time.zone = nil
ActiveRecord::Base.default_timezone = :utc
self.default_timezone = :utc
expect(described_class.db_time_now.zone).to eq "UTC"
end

it "returns local time if that is the AR default" do
Time.zone = "Arizona"
ActiveRecord::Base.default_timezone = :local
self.default_timezone = :local
expect(described_class.db_time_now.zone).to eq("MST")
end
end
Expand Down
11 changes: 9 additions & 2 deletions spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,15 @@ class SingletonClass
end
end

# Add this directory so the ActiveSupport autoloading works
ActiveSupport::Dependencies.autoload_paths << File.dirname(__FILE__)
if ActiveRecord::VERSION::MAJOR >= 7
require "zeitwerk"
loader = Zeitwerk::Loader.new
loader.push_dir File.dirname(__FILE__)
loader.setup
else
# Add this directory so the ActiveSupport autoloading works
ActiveSupport::Dependencies.autoload_paths << File.dirname(__FILE__)
end

RSpec::Matchers.define :emit_notification do |expected_event_name|
attr_reader :actual, :expected
Expand Down
2 changes: 1 addition & 1 deletion spec/yaml_ext_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
it 'autoloads the class of an anonymous struct' do
expect {
yaml = "--- !ruby/struct\nn: 1\n"
object = YAML.load(yaml)
object = load_with_delayed_visitor(yaml)
expect(object).to be_kind_of(Struct)
expect(object.n).to eq(1)
}.not_to raise_error
Expand Down

0 comments on commit 2d296b9

Please sign in to comment.