Skip to content

Commit

Permalink
sometimes search indexing becomes broken (#3591)
Browse files Browse the repository at this point in the history
  • Loading branch information
akostadinov authored Nov 2, 2023
1 parent 8865ce7 commit 32430a8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/workers/sphinx_indexation_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class SphinxIndexationWorker < ApplicationJob
Rails.logger.info "SphinxIndexationWorker#perform raised #{exception.class} with message #{exception.message}"
end

rescue_from(ThinkingSphinx::QueryError) do |exception|
ThinkingSphinx::Connection.clear if exception.message.include?("unknown column")
raise
end

def perform(model, id)
instance = model.find_by(model.primary_key => id)

Expand Down
20 changes: 20 additions & 0 deletions test/workers/sphinx_indexation_worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,24 @@ class SphinxIndexationWorkerTest < ActiveSupport::TestCase
enable_search_jobs!
SphinxIndexationWorker.perform_now(ThinkingSphinx::Test.indexed_models.sample, 42)
end

test "it re-establishes sphinx connections on certain errors" do
enable_search_jobs!
SphinxIndexationWorker.any_instance.expects(:perform).raises(ThinkingSphinx::QueryError, "unknown column: 'sphinx_internal_class_name' - REPLACE INTO account_core (id, `sphinx_internal_class_name`, `name`, `account_id`, `username`, `user_full_name`, `email`, `user_key`, `app_id`, `app_name`, `user_id`, `sphinx_internal_id`, `sphinx_internal_class`, `sphinx_deleted`, `sphinx_updated_at`, `provider_account_id`, `tenant_id`, `state`) VALUES (14978, 'Account', 'org_name-lkdjfggf-serch-yyith8w', '156', 'username-lkdjfggf-serch-xskw25c', ' ', '[email protected]', 'af61253a5933dd9ba30bebb6661d16d1 ede2926ef59ecdc45da4a8960164ffc2', '3173be1c fc507eb9', 'org_name-lkdjfggf-serch-yyith8w's App ui_accou-lkdjfggf-accont-vmt8wba', '180', 156, 'Account', 0, 1697580778, 2, 2, 'approved')")
ThinkingSphinx::Connection.expects(:clear)

assert_raises(ThinkingSphinx::QueryError) do
SphinxIndexationWorker.perform_now(ThinkingSphinx::Test.indexed_models.sample, 42)
end
end

test "it doesn't re-establishes sphinx connections on random errors" do
enable_search_jobs!
SphinxIndexationWorker.any_instance.expects(:perform).raises(RuntimeError, "whatever error")
ThinkingSphinx::Connection.expects(:clear).never

assert_raises(RuntimeError) do
SphinxIndexationWorker.perform_now(ThinkingSphinx::Test.indexed_models.sample, 42)
end
end
end

0 comments on commit 32430a8

Please sign in to comment.