Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOL-127: Add Ruby 3 support to gem #2

Merged
merged 33 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d5e43b4
* Support for Ruby 3.0 added
webhoernchen Dec 22, 2020
7c73130
* debug messages commented out
webhoernchen Dec 22, 2020
bfdabfe
* syntax fixed
webhoernchen Dec 22, 2020
90faa82
* Syntax fixed
webhoernchen Dec 22, 2020
34dc5c9
* Syntax fixed
webhoernchen Dec 22, 2020
c93b433
* specs added
webhoernchen Mar 27, 2021
87a2aef
* Ruby 3.0 added
webhoernchen Mar 27, 2021
8903aaa
* ci fixed
webhoernchen Mar 27, 2021
25b0a43
* dependencies fixed
webhoernchen Mar 27, 2021
7819cb8
* rubocop fixed
webhoernchen Mar 28, 2021
fff4e1e
* specs for older rails versions fixed
webhoernchen Mar 28, 2021
0afc6a2
* specs for old rails versions fixed
webhoernchen Mar 28, 2021
1e97748
+ specs for old rails versions fixed
webhoernchen Mar 28, 2021
e8b520e
Capture kwargs separately in PerformableMethod
jdelStrother Nov 8, 2021
f379d6a
Try to maintain support for ruby 2.6
jdelStrother Nov 9, 2021
2151092
Merge remote-tracking branch 'delayed-job-ruby3/ruby3' into ruby3
m-dwyer Apr 20, 2022
b5fff18
Add initional github specific files, including actions, pull request …
m-dwyer Apr 20, 2022
a1357f7
Add ruby workflow based on existing event_framework to run tests
m-dwyer Apr 20, 2022
de28325
Fix expectations for hash passed inside args. args array will be unp…
m-dwyer Apr 20, 2022
eb3d8e0
Upgrade rubocop for ruby 3 support, and silence offenses
m-dwyer Apr 20, 2022
8f85ff6
Add catalog info for backstage
m-dwyer May 4, 2022
f5a71f7
Update .github/CODEOWNERS
m-dwyer May 4, 2022
9ad0510
Remove unneeded teams.yaml file
m-dwyer May 4, 2022
1f8d1eb
remove unneeded team labeler step
m-dwyer May 4, 2022
6d3b3e1
add ruby version matrix
m-dwyer May 4, 2022
58b5086
Merge branch 'ruby3' of github.com:cultureamp/delayed_job into ruby3
m-dwyer May 4, 2022
f15251c
Slight refactor, and allow for proxying method with no args, args, ar…
m-dwyer May 6, 2022
6f47bd3
Allow for args without kwargs
m-dwyer May 6, 2022
b25f26d
Revert default opts hash ruby 2.x changes
m-dwyer May 9, 2022
b4ed9da
Refactor perform into ruby2 and ruby3 methods
m-dwyer May 9, 2022
c50a1e7
Clean up dynamic method_missing definition
m-dwyer May 13, 2022
34bd663
Explicitly require kernel extension for silence_warnings method
m-dwyer May 13, 2022
1b42784
Move kwargs to attr_writer given method override to avoid ambiguity
m-dwyer May 13, 2022
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
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Team Sol is taking ownership over delayed job infrastructure.
# This will notify us of any requested changes to anything
* @cultureamp/sol
27 changes: 27 additions & 0 deletions .github/pull_request_checklist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Pull Request Checklist Details

Here are some useful questions to ask before merging a Pull Request.

## [Security](https://cultureamp.atlassian.net/wiki/spaces/SEC/pages/963641883/Security+Partnership+Process)
- [Do we need an AppSec review?](https://cultureamp.atlassian.net/servicedesk/customer/portal/5/group/39/create/461)
- Have we modified authentication, authorization, filtering?
- Could there be any PII leaks through tracking or logging?

## Acceptance Criteria
- What is the acceptance criteria?
- How can we verify the PR has the desired effect?
- Are we sure there are no undesired side effects?

## Tests
- Do we have appropriate tests?
- How much of the new code do they cover?
- What gaps do you need to call out?

## Logging
- Are we logging the right things?
- Are we using structured logging?

## Involve Others
- [Do we need a Change Management Request?](https://cultureamp.atlassian.net/servicedesk/customer/portal/30)
- Does the tech lead need to see this?
- Do other teams need to see this?
35 changes: 35 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!--

Just fill in only the relevant sections unless you are linking to trello/jira

-->

## Purpose
<!--
What is the objective of the Pull Request?
-->

## Context
<!--
Why are we making this change?
Is there jira/trello, bugsnag or slack link you can put here?
If it was a bug, what caused it?
-->

## Changes
<!--
What were the changes you made? (Omit section if this is clear from the commits already.)
-->

## Verification
<!--
Any exceptions to testing norms?
Where should QA focus?
-->

## Checklist
- [Security](pull_request_checklist.md#security)
- [Acceptance Criteria](pull_request_checklist.md#acceptance%20criteria)
- [Tests](pull_request_checklist.md#tests)
- [Logging](pull_request_checklist.md#logging)
- [Involve Others](pull_request_checklist.md#involve%20others)
92 changes: 0 additions & 92 deletions .github/workflows/ci.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up Ruby 2.7
- name: Set up Ruby 3.0
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
ruby-version: 3.0
- name: Generate lockfile for cache key
run: bundle lock
- name: Cache gems
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Tests
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
tests:
strategy:
matrix:
version: [2.7.5, 3.0.4]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.version }}
- name: Install dependencies
run: bundle install
- name: Run tests
run: bundle exec rspec
20 changes: 13 additions & 7 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ AllCops:
- 'Gemfile'
- 'Rakefile'
- 'delayed_job.gemspec'
TargetRubyVersion: 2.1

RedundantBlockCall:
Enabled: false
TargetRubyVersion: 3.0

BlockLength:
Enabled: false
Expand Down Expand Up @@ -133,9 +130,6 @@ Style/SymbolArray:
SymbolProc:
Enabled: false

TrailingCommaInLiteral:
Enabled: false

TrailingCommaInArguments:
Enabled: false

Expand All @@ -144,3 +138,15 @@ YAMLLoad:

ZeroLengthPredicate:
Enabled: false

Style/IfUnlessModifier:
Enabled: false

Style/CaseLikeIf:
Enabled: false

Gemspec/RequiredRubyVersion:
Enabled: false

Migration/DepartmentName:
Enabled: false
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ group :test do
end

group :rubocop do
gem 'rubocop', '>= 0.25', '< 0.49'
gem 'rubocop', '~>1.27.0'
end

gemspec
19 changes: 19 additions & 0 deletions catalog-info-component.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: delayed_job
description: Forked delayed_job gem with ruby 3 support
links:
- title: Github
url: https://github.com/cultureamp/delayed_job
tags:
- users-internal
- camp-engagement
- data-none
annotations:
github.com/project-slug: cultureamp/delayed_job
github.com/team-slug: cultureamp/sol
spec:
type: library
owner: sol
lifecycle: development
9 changes: 9 additions & 0 deletions catalog-info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: backstage.io/v1alpha1
kind: Location
metadata:
name: delayed_job-location
tags:
- camp-engagement
spec:
targets:
- ./catalog-info-component.yaml # this is your main component file
2 changes: 1 addition & 1 deletion delayed_job.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
spec.test_files = Dir.glob('spec/**/*')
spec.version = '4.1.10'
spec.metadata = {
'changelog_uri' => 'https://github.com/collectiveidea/delayed_job/blob/master/CHANGELOG.md',
'changelog_uri' => 'https://github.com/collectiveidea/delayed_job/blob/master/CHANGELOG.md',
'bug_tracker_uri' => 'https://github.com/collectiveidea/delayed_job/issues',
'source_code_uri' => 'https://github.com/collectiveidea/delayed_job'
}
Expand Down
1 change: 1 addition & 0 deletions lib/delayed/backend/shared_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require File.expand_path('../../../../spec/sample_jobs', __FILE__)

require 'active_support/core_ext/numeric/time'
require 'active_support/core_ext/kernel/reporting'

shared_examples_for 'a delayed_job backend' do
let(:worker) { Delayed::Worker.new }
Expand Down
4 changes: 2 additions & 2 deletions lib/delayed/message_sending.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def initialize(payload_class, target, options)
end

# rubocop:disable MethodMissing
def method_missing(method, *args)
Job.enqueue({:payload_object => @payload_class.new(@target, method.to_sym, args)}.merge(@options))
def method_missing(method, *args, **kwargs)
Job.enqueue({:payload_object => @payload_class.new(@target, method.to_sym, args, kwargs)}.merge(@options))
end
# rubocop:enable MethodMissing
end
Expand Down
2 changes: 1 addition & 1 deletion lib/delayed/performable_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Delayed
class PerformableMailer < PerformableMethod
def perform
mailer = object.send(method_name, *args)
mailer = super
mailer.respond_to?(:deliver_now) ? mailer.deliver_now : mailer.deliver
end
end
Expand Down
43 changes: 37 additions & 6 deletions lib/delayed/performable_method.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module Delayed
class PerformableMethod
attr_accessor :object, :method_name, :args
attr_writer :kwargs

def initialize(object, method_name, args)
def initialize(object, method_name, args, kwargs = {})
raise NoMethodError, "undefined method `#{method_name}' for #{object.inspect}" unless object.respond_to?(method_name, true)

if object.respond_to?(:persisted?) && !object.persisted?
Expand All @@ -11,6 +12,7 @@ def initialize(object, method_name, args)

self.object = object
self.args = args
self.kwargs = kwargs
self.method_name = method_name.to_sym
end

Expand All @@ -22,22 +24,51 @@ def display_name
end
end

def kwargs
m-dwyer marked this conversation as resolved.
Show resolved Hide resolved
# Default to a hash so that we can handle deserializing jobs that were
# created before kwargs was available.
@kwargs || {}
end

def perform
object.send(method_name, *args) if object
if RUBY_VERSION >= '3.0'
ruby3_perform
else
ruby2_perform
end
end

def method(sym)
object.method(sym)
end

# rubocop:disable MethodMissing
def method_missing(symbol, *args)
object.send(symbol, *args)
end
definition = RUBY_VERSION >= '2.7' ? '...' : '*args, &block'
module_eval <<-RUBY, __FILE__, __LINE__ + 1
def method_missing(#{definition})
object.send(#{definition})
end
RUBY
# rubocop:enable MethodMissing

def respond_to?(symbol, include_private = false)
super || object.respond_to?(symbol, include_private)
end

private

def ruby2_perform
# In ruby 2, rely on the implicit conversion from a hash to kwargs
return unless object
if kwargs.present?
object.send(method_name, *args, kwargs)
else
object.send(method_name, *args)
end
end

def ruby3_perform
# In ruby 3 we need to explicitly separate regular args from the keyword-args.
object.send(method_name, *args, **kwargs) if object
end
end
end
3 changes: 2 additions & 1 deletion lib/delayed/psych_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ def encode_with(coder)
coder.map = {
'object' => object,
'method_name' => method_name,
'args' => args
'args' => args,
'kwargs' => kwargs
}
end
end
Expand Down
Loading