Commit 3b261c3e authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab master

parents 329ce025 96110427
......@@ -53,6 +53,8 @@ module Gitlab
# 'args' in :job => from default error handler
job_holder = sidekiq.key?('args') ? sidekiq : sidekiq[:job]
return event unless job_holder
if job_holder['args']
job_holder['args'] = filter_arguments(job_holder['args'], job_holder['class']).to_a
end
......
......@@ -11,9 +11,8 @@ module RuboCop
ENFORCED_SINCE = 2020_02_12_00_00_00
MSG = <<~MSG
Don't call the background migration worker directly, use the `#migrate_async`,
`#migrate_in`, `#bulk_migrate_async` or `#bulk_migrate_in` migration helpers
instead.
Don't call the background migration worker directly, use the `#migrate_in` or
`#queue_background_migration_jobs_by_range_at_intervals` migration helpers instead.
MSG
def_node_matcher :calls_background_migration_worker?, <<~PATTERN
......@@ -26,28 +25,6 @@ module RuboCop
add_offense(node, location: :expression) if calls_background_migration_worker?(node)
end
def autocorrect(node)
# This gets rid of the receiver `BackgroundMigrationWorker` and
# replaces `perform` with `schedule`
schedule_method = method_name(node).to_s.sub('perform', 'migrate')
arguments = arguments(node).map(&:source).join(', ')
replacement = "#{schedule_method}(#{arguments})"
lambda do |corrector|
corrector.replace(node.source_range, replacement)
end
end
private
def method_name(node)
node.children.second
end
def arguments(node)
node.children[2..]
end
end
end
end
......
......@@ -178,5 +178,14 @@ RSpec.describe Gitlab::ErrorTracking::Processor::SidekiqProcessor do
expect(result_hash.dig(:extra, :sidekiq)).to be_nil
end
end
context 'when there is Sidekiq data but no job' do
let(:value) { { other: 'foo' } }
let(:wrapped_value) { { extra: { sidekiq: value } } }
it 'does nothing' do
expect(result_hash.dig(:extra, :sidekiq)).to eq(value)
end
end
end
end
......@@ -43,24 +43,18 @@ RSpec.describe RuboCop::Cop::Migration::ScheduleAsync do
end
context 'BackgroundMigrationWorker.perform_async' do
it 'adds an offense when calling `BackgroundMigrationWorker.peform_async` and corrects', :aggregate_failures do
it 'adds an offense when calling `BackgroundMigrationWorker.peform_async`' do
expect_offense(<<~RUBY)
def up
BackgroundMigrationWorker.perform_async(ClazzName, "Bar", "Baz")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't call [...]
end
RUBY
expect_correction(<<~RUBY)
def up
migrate_async(ClazzName, "Bar", "Baz")
end
RUBY
end
end
context 'BackgroundMigrationWorker.perform_in' do
it 'adds an offense and corrects', :aggregate_failures do
it 'adds an offense' do
expect_offense(<<~RUBY)
def up
BackgroundMigrationWorker
......@@ -68,17 +62,11 @@ RSpec.describe RuboCop::Cop::Migration::ScheduleAsync do
.perform_in(delay, ClazzName, "Bar", "Baz")
end
RUBY
expect_correction(<<~RUBY)
def up
migrate_in(delay, ClazzName, "Bar", "Baz")
end
RUBY
end
end
context 'BackgroundMigrationWorker.bulk_perform_async' do
it 'adds an offense and corrects', :aggregate_failures do
it 'adds an offense' do
expect_offense(<<~RUBY)
def up
BackgroundMigrationWorker
......@@ -86,17 +74,11 @@ RSpec.describe RuboCop::Cop::Migration::ScheduleAsync do
.bulk_perform_async(jobs)
end
RUBY
expect_correction(<<~RUBY)
def up
bulk_migrate_async(jobs)
end
RUBY
end
end
context 'BackgroundMigrationWorker.bulk_perform_in' do
it 'adds an offense and corrects', :aggregate_failures do
it 'adds an offense' do
expect_offense(<<~RUBY)
def up
BackgroundMigrationWorker
......@@ -104,12 +86,6 @@ RSpec.describe RuboCop::Cop::Migration::ScheduleAsync do
.bulk_perform_in(5.minutes, jobs)
end
RUBY
expect_correction(<<~RUBY)
def up
bulk_migrate_in(5.minutes, jobs)
end
RUBY
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment