Maintenance: Perform SearchIndexJob and SearchIndexAssociationsJob actions to reduce job numbers.

This commit is contained in:
Thorsten Eckel 2021-05-18 09:50:28 +02:00
parent 85d6e19892
commit f06dc08502
4 changed files with 7 additions and 7 deletions

View file

@ -1,6 +1,7 @@
class SearchIndexAssociationsJob < SearchIndexJob
def update_search_index(record)
super
record.search_index_update_associations_delta
record.search_index_update_associations_full
end

View file

@ -24,7 +24,6 @@ update search index, if configured - will be executed automatically
# start background job to transfer data to search index
return true if !SearchIndexBackend.enabled?
SearchIndexJob.perform_later(self.class.to_s, id)
SearchIndexAssociationsJob.perform_later(self.class.to_s, id)
true
end

View file

@ -14,13 +14,13 @@ RSpec.shared_examples 'HasSearchIndexBackend' do |indexed_factory:|
end
it 'indexes on create' do
expect(SearchIndexJob).to have_been_enqueued
expect(SearchIndexAssociationsJob).to have_been_enqueued
end
it 'indexes on update' do
clear_jobs
subject.update(note: 'Updated')
expect(SearchIndexJob).to have_been_enqueued
expect(SearchIndexAssociationsJob).to have_been_enqueued
end
it 'indexes on touch' do

View file

@ -610,7 +610,7 @@ RSpec.describe 'Monitoring', type: :request do
expect(json_response['message']).to be_truthy
expect(json_response['issues']).to be_truthy
expect(json_response['healthy']).to eq(false)
expect( json_response['message']).to eq("Failed to run background job #1 'SearchIndexAssociationsJob' 1 time(s) with 1 attempt(s).;Failed to run background job #2 'SearchIndexJob' 1 time(s) with 1 attempt(s).")
expect( json_response['message']).to eq("Failed to run background job #1 'SearchIndexAssociationsJob' 1 time(s) with 1 attempt(s).")
# add another job
manual_added = SearchIndexJob.perform_later('Ticket', 1)
@ -624,7 +624,7 @@ RSpec.describe 'Monitoring', type: :request do
expect(json_response['message']).to be_truthy
expect(json_response['issues']).to be_truthy
expect(json_response['healthy']).to eq(false)
expect( json_response['message']).to eq("Failed to run background job #1 'SearchIndexAssociationsJob' 1 time(s) with 1 attempt(s).;Failed to run background job #2 'SearchIndexJob' 2 time(s) with 11 attempt(s).")
expect( json_response['message']).to eq("Failed to run background job #1 'SearchIndexAssociationsJob' 1 time(s) with 1 attempt(s).;Failed to run background job #2 'SearchIndexJob' 1 time(s) with 10 attempt(s).")
# add another job
dummy_class = Class.new(ApplicationJob) do
@ -645,7 +645,7 @@ RSpec.describe 'Monitoring', type: :request do
expect(json_response['message']).to be_truthy
expect(json_response['issues']).to be_truthy
expect(json_response['healthy']).to eq(false)
expect(json_response['message']).to eq("Failed to run background job #1 'Object' 1 time(s) with 5 attempt(s).;Failed to run background job #2 'SearchIndexAssociationsJob' 1 time(s) with 1 attempt(s).;Failed to run background job #3 'SearchIndexJob' 2 time(s) with 11 attempt(s).")
expect(json_response['message']).to eq("Failed to run background job #1 'Object' 1 time(s) with 5 attempt(s).;Failed to run background job #2 'SearchIndexAssociationsJob' 1 time(s) with 1 attempt(s).;Failed to run background job #3 'SearchIndexJob' 1 time(s) with 10 attempt(s).")
# reset settings
Setting.set('es_url', prev_es_config)
@ -664,7 +664,7 @@ RSpec.describe 'Monitoring', type: :request do
expect(json_response['message']).to be_truthy
expect(json_response['issues']).to be_truthy
expect(json_response['healthy']).to eq(false)
expect(json_response['message']).to eq("14 failing background jobs;Failed to run background job #1 'Object' 7 time(s) with 35 attempt(s).;Failed to run background job #2 'SearchIndexAssociationsJob' 1 time(s) with 1 attempt(s).;Failed to run background job #3 'SearchIndexJob' 2 time(s) with 11 attempt(s).")
expect(json_response['message']).to eq("13 failing background jobs;Failed to run background job #1 'Object' 8 time(s) with 40 attempt(s).;Failed to run background job #2 'SearchIndexAssociationsJob' 1 time(s) with 1 attempt(s).;Failed to run background job #3 'SearchIndexJob' 1 time(s) with 10 attempt(s).")
# cleanup
Delayed::Job.delete_all