2020-04-08 14:13:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require_relative '../../migration_helpers'
|
|
|
|
|
|
|
|
module RuboCop
|
|
|
|
module Cop
|
|
|
|
module Migration
|
2022-10-11 01:57:18 +05:30
|
|
|
class ScheduleAsync < RuboCop::Cop::Base
|
2020-04-08 14:13:33 +05:30
|
|
|
include MigrationHelpers
|
|
|
|
|
|
|
|
ENFORCED_SINCE = 2020_02_12_00_00_00
|
|
|
|
|
|
|
|
MSG = <<~MSG
|
2022-03-02 08:16:31 +05:30
|
|
|
Don't call the background migration worker directly, use the `#migrate_in` or
|
|
|
|
`#queue_background_migration_jobs_by_range_at_intervals` migration helpers instead.
|
2020-04-08 14:13:33 +05:30
|
|
|
MSG
|
|
|
|
|
|
|
|
def_node_matcher :calls_background_migration_worker?, <<~PATTERN
|
2022-04-04 11:22:00 +05:30
|
|
|
(send (const {cbase nil?} :BackgroundMigrationWorker) #perform_method? ...)
|
|
|
|
PATTERN
|
|
|
|
|
|
|
|
def_node_matcher :calls_ci_database_worker?, <<~PATTERN
|
|
|
|
(send (const {(const {cbase nil?} :BackgroundMigration) nil?} :CiDatabaseWorker) #perform_method? ...)
|
|
|
|
PATTERN
|
|
|
|
|
|
|
|
def_node_matcher :perform_method?, <<~PATTERN
|
|
|
|
{:perform_async :bulk_perform_async :perform_in :bulk_perform_in}
|
2020-04-08 14:13:33 +05:30
|
|
|
PATTERN
|
|
|
|
|
|
|
|
def on_send(node)
|
|
|
|
return unless in_migration?(node)
|
|
|
|
return if version(node) < ENFORCED_SINCE
|
2022-04-04 11:22:00 +05:30
|
|
|
return unless calls_background_migration_worker?(node) || calls_ci_database_worker?(node)
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
add_offense(node)
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|