Skip to content
代码片段 群组 项目
未验证 提交 9255d68a 编辑于 作者: Terri Chu's avatar Terri Chu 提交者: GitLab
浏览文件

Do not delay indexing for dev envs

上级 12592f7e
No related branches found
No related tags found
无相关合并请求
......@@ -9,6 +9,7 @@ class TriggerIndexingWorker
INITIAL_TASK = :initiate
TASKS = %i[namespaces projects snippets users].freeze
DEFAULT_DELAY = 2.minutes
data_consistency :delayed
......@@ -55,15 +56,14 @@ def initiate
).execute
logger.info('Setting `elasticsearch_indexing` has been enabled.')
self.class.perform_in(2.minutes, INITIAL_TASK, options)
reenqueue_initial_task
return false
end
unless ::Gitlab::CurrentSettings.elasticsearch_pause_indexing?
task_executor_service.execute(:pause_indexing)
self.class.perform_in(2.minutes, INITIAL_TASK, options)
reenqueue_initial_task
return false
end
......@@ -87,6 +87,14 @@ def task_executor_service
def logger
@logger ||= ::Gitlab::Elasticsearch::Logger.build
end
def reenqueue_initial_task
if Rails.env.development?
self.class.perform_async(INITIAL_TASK, options)
else
self.class.perform_in(DEFAULT_DELAY, INITIAL_TASK, options)
end
end
end
end
end
......@@ -88,10 +88,24 @@
it 'pauses indexing and reschedules itself' do
expect(task_executor_service).to receive(:execute).with(:pause_indexing)
expect(described_class).to receive(:perform_in).with(2.minutes, described_class::INITIAL_TASK, {})
expect(described_class).to receive(:perform_in)
.with(described_class::DEFAULT_DELAY, described_class::INITIAL_TASK, {})
expect(perform).to be false
end
context 'when in development environment' do
before do
stub_rails_env('development')
end
it 'pauses indexing and runs itself without delay' do
expect(task_executor_service).to receive(:execute).with(:pause_indexing)
expect(described_class).to receive(:perform_async).with(described_class::INITIAL_TASK, {})
expect(perform).to be false
end
end
end
context 'when indexing is disabled' do
......@@ -105,10 +119,28 @@
nil,
{ elasticsearch_indexing: true }).and_call_original
expect(task_executor_service).not_to receive(:execute)
expect(described_class).to receive(:perform_in).with(2.minutes, described_class::INITIAL_TASK, {})
expect(described_class).to receive(:perform_in)
.with(described_class::DEFAULT_DELAY, described_class::INITIAL_TASK, {})
expect(perform).to be false
end
context 'when in development environment' do
before do
stub_rails_env('development')
end
it 'enables indexing and runs itself without delay' do
expect(ApplicationSettings::UpdateService).to receive(:new).with(
Gitlab::CurrentSettings.current_application_settings,
nil,
{ elasticsearch_indexing: true }).and_call_original
expect(task_executor_service).not_to receive(:execute)
expect(described_class).to receive(:perform_async).with(described_class::INITIAL_TASK, {})
expect(perform).to be false
end
end
end
end
end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册