diff --git a/Rakefile b/Rakefile index 591d2c4c6..2e996417e 100644 --- a/Rakefile +++ b/Rakefile @@ -2,9 +2,8 @@ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require_relative 'config/application' +# Load Enterprise Edition rake tasks if they exist +enterprise_tasks_path = Rails.root.join('enterprise/tasks_railtie.rb').to_s +require enterprise_tasks_path if File.exist?(enterprise_tasks_path) Rails.application.load_tasks - -# Load Enterprise Edition rake tasks if they exist -enterprise_tasks_path = Rails.root.join('enterprise/lib/tasks.rb').to_s -require enterprise_tasks_path if File.exist?(enterprise_tasks_path) diff --git a/enterprise/lib/tasks.rb b/enterprise/lib/tasks.rb deleted file mode 100644 index 139819bbb..000000000 --- a/enterprise/lib/tasks.rb +++ /dev/null @@ -1,4 +0,0 @@ -# Load all rake tasks from the enterprise/lib/tasks directory -module Tasks - Dir.glob(File.join(File.dirname(__FILE__), 'tasks', '*.rake')).each { |r| load r } -end diff --git a/enterprise/lib/tasks/search.rake b/enterprise/lib/tasks/search.rake index 03bad2c1b..4ec137434 100644 --- a/enterprise/lib/tasks/search.rake +++ b/enterprise/lib/tasks/search.rake @@ -1,22 +1,4 @@ -module Tasks::SearchTaskHelpers - def check_opensearch_config - if ENV['OPENSEARCH_URL'].blank? - puts 'Skipping reindex as OPENSEARCH_URL is not configured' - return false - end - true - end - - def reindex_account(account) - Messages::ReindexService.new(account: account).perform - puts "Reindex task queued for account #{account.id}" - end -end - namespace :search do - desc 'Reindex messages using searchkick' - include Tasks::SearchTaskHelpers - desc 'Reindex messages for all accounts' task all: :environment do next unless check_opensearch_config @@ -47,3 +29,16 @@ namespace :search do reindex_account(account) end end + +def check_opensearch_config + if ENV['OPENSEARCH_URL'].blank? + puts 'Skipping reindex as OPENSEARCH_URL is not configured' + return false + end + true +end + +def reindex_account(account) + Messages::ReindexService.new(account: account).perform + puts "Reindex task queued for account #{account.id}" +end diff --git a/enterprise/tasks_railtie.rb b/enterprise/tasks_railtie.rb new file mode 100644 index 000000000..9a7d09360 --- /dev/null +++ b/enterprise/tasks_railtie.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class TasksRailtie < Rails::Railtie + rake_tasks do + # Load all rake tasks from enterprise/lib/tasks + Dir.glob(Rails.root.join('enterprise/lib/tasks/**/*.rake')).each { |f| load f } + end +end