Commit 4b491b00 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '323856-indexer-add-timeout' into 'master'

Add timeout for gitlab-elasticsearch-indexer

See merge request gitlab-org/gitlab!62366
parents 03326487 be5ddaf6
......@@ -23,7 +23,7 @@ class ElasticCommitIndexerWorker
project = Project.find(project_id)
return true unless project.use_elasticsearch?
in_lock("#{self.class.name}/#{project_id}/#{wiki}", ttl: 1.day, retries: 0) do
in_lock("#{self.class.name}/#{project_id}/#{wiki}", ttl: (Gitlab::Elastic::Indexer::TIMEOUT + 1.minute), retries: 0) do
Gitlab::Elastic::Indexer.new(project, wiki: wiki).run
end
end
......
......@@ -8,6 +8,8 @@ module Gitlab
class Indexer
include Gitlab::Utils::StrongMemoize
TIMEOUT = 1.day.to_i
Error = Class.new(StandardError)
class << self
......@@ -73,11 +75,13 @@ module Gitlab
vars = build_envvars(base_sha, to_sha, target)
path_to_indexer = Gitlab.config.elasticsearch.indexer_path
timeout_argument = "--timeout=#{TIMEOUT}s"
command =
if index_wiki?
[path_to_indexer, "--blob-type=wiki_blob", "--skip-commits", "--project-path=#{project.full_path}", project.id.to_s, repository_path]
[path_to_indexer, timeout_argument, "--blob-type=wiki_blob", "--skip-commits", "--project-path=#{project.full_path}", project.id.to_s, repository_path]
else
[path_to_indexer, "--project-path=#{project.full_path}", project.id.to_s, repository_path]
[path_to_indexer, timeout_argument, "--project-path=#{project.full_path}", project.id.to_s, repository_path]
end
output, status = Gitlab::Popen.popen(command, nil, vars)
......
......@@ -92,6 +92,7 @@ RSpec.describe Gitlab::Elastic::Indexer do
expect_popen.with(
[
TestEnv.indexer_bin_path,
"--timeout=#{Gitlab::Elastic::Indexer::TIMEOUT}s",
"--project-path=#{project.full_path}",
project.id.to_s,
"#{project.repository.disk_path}.git"
......@@ -213,6 +214,7 @@ RSpec.describe Gitlab::Elastic::Indexer do
expect_popen.with(
[
TestEnv.indexer_bin_path,
"--timeout=#{Gitlab::Elastic::Indexer::TIMEOUT}s",
'--blob-type=wiki_blob',
'--skip-commits',
"--project-path=#{project.full_path}",
......
......@@ -37,7 +37,7 @@ RSpec.describe ElasticCommitIndexerWorker do
it 'does not run index when it is locked' do
expect(subject).to receive(:in_lock) # Mock and don't yield
.with("ElasticCommitIndexerWorker/#{project.id}/false", ttl: 1.day, retries: 0)
.with("ElasticCommitIndexerWorker/#{project.id}/false", ttl: (Gitlab::Elastic::Indexer::TIMEOUT + 1.minute), retries: 0)
expect(Gitlab::Elastic::Indexer).not_to receive(:new)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment