Commit f26488a7 authored by Valery Sizov's avatar Valery Sizov

ES: namespace refactoring

parent 8c599cd0
......@@ -94,7 +94,7 @@ class GitPushService < BaseService
end
def index_commits_blobs
indexer = Elastic::Indexer.new
indexer = Gitlab::Elastic::Indexer.new
indexer.run(
@project.id,
project.repository.path_to_repo,
......
module Elastic
class Indexer
Error = Class.new(StandardError)
def initialize
connection_info = {
host: Gitlab.config.elasticsearch.host,
port: Gitlab.config.elasticsearch.port
}.to_json
# We accept any form of settings, including string and array
# This is why JSON is needed
@vars = {
'ELASTIC_CONNECTION_INFO' => connection_info,
'RAILS_ENV' => Rails.env
}
end
def run(project_id, repo_path, from_sha = nil, to_sha = nil)
to_sha = nil if to_sha == Gitlab::Git::BLANK_SHA
vars = @vars.merge({ 'FROM_SHA' => from_sha, 'TO_SHA' => to_sha })
path_to_indexer = File.join(Rails.root, 'bin/elastic_repo_indexer')
command = [path_to_indexer, project_id.to_s, repo_path]
output, status = Gitlab::Popen.popen(command, nil, vars)
raise Error, output unless status.zero?
true
end
end
end
module Gitlab
module Elastic
class Indexer
Error = Class.new(StandardError)
def initialize
connection_info = {
host: Gitlab.config.elasticsearch.host,
port: Gitlab.config.elasticsearch.port
}.to_json
# We accept any form of settings, including string and array
# This is why JSON is needed
@vars = {
'ELASTIC_CONNECTION_INFO' => connection_info,
'RAILS_ENV' => Rails.env
}
end
def run(project_id, repo_path, from_sha = nil, to_sha = nil)
to_sha = nil if to_sha == Gitlab::Git::BLANK_SHA
vars = @vars.merge({ 'FROM_SHA' => from_sha, 'TO_SHA' => to_sha })
path_to_indexer = File.join(Rails.root, 'bin/elastic_repo_indexer')
command = [path_to_indexer, project_id.to_s, repo_path]
output, status = Gitlab::Popen.popen(command, nil, vars)
raise Error, output unless status.zero?
true
end
end
end
end
......@@ -21,7 +21,7 @@ namespace :gitlab do
projects = apply_project_filters(projects)
indexer = Elastic::Indexer.new
indexer = Gitlab::Elastic::Indexer.new
projects.find_each do |project|
repository = project.repository
......
......@@ -16,6 +16,6 @@ describe "Indexer" do
)
).and_return([[''], 0])
Elastic::Indexer.new.run(1, 'full_repo_path', '000000', '1d1f2d')
Gitlab::Elastic::Indexer.new.run(1, 'full_repo_path', '000000', '1d1f2d')
end
end
......@@ -147,7 +147,7 @@ describe GitPushService, services: true do
end
it "triggers indexer" do
expect_any_instance_of(Elastic::Indexer).to receive(:run)
expect_any_instance_of(Gitlab::Elastic::Indexer).to receive(:run)
execute_service(project, user, @oldrev, @newrev, @ref )
end
......
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