fix: Search rake task causing Rails boot error (#12416)

## Description

This PR sets up an `Enterprise::Railtie` to correctly register rake
tasks in the `enterprise` namespace.
Previously, rake tasks under `enterprise/lib/tasks` were being eagerly
loaded at Rails boot, causing `undefined method 'namespace'` errors.

With this change, rake tasks are now registered only in the rake
context, avoiding boot-time issues and ensuring they are discoverable
with `bin/rake -T`.

**Tasks added:**

* `search:all` → Reindex messages for all accounts
* `search:account[ID]` → Reindex messages for a specific account

Fixes: #12414


Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
Akshay Borade
2025-09-15 22:21:59 +05:30
committed by GitHub
parent fc92e118ed
commit f590539b9b
4 changed files with 24 additions and 26 deletions

View File

@@ -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