Skip to content

Commit

Permalink
Merge pull request #2 from cultureamp/ruby3
Browse files Browse the repository at this point in the history
SOL-127: Add Ruby 3 support to gem
  • Loading branch information
m-dwyer authored May 20, 2022
2 parents 11e0212 + 1b42784 commit 324347b
Show file tree
Hide file tree
Showing 20 changed files with 303 additions and 114 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
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
# 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

0 comments on commit 324347b

Please sign in to comment.