Commit 8103470d authored by Toon Claes's avatar Toon Claes

Use services to schedule workers in geo log daemon

Instead of scheduling the workers from the code, use service with
`async_execute` instead.
parent 1547a899
...@@ -11,6 +11,10 @@ module Geo ...@@ -11,6 +11,10 @@ module Geo
@new_path_with_namespace = new_path_with_namespace @new_path_with_namespace = new_path_with_namespace
end end
def async_execute
GeoRepositoryMoveWorker.perform_async(id, name, old_path_with_namespace, new_path_with_namespace)
end
def execute def execute
project = Project.find(id) project = Project.find(id)
project.expire_caches_before_rename(old_path_with_namespace) project.expire_caches_before_rename(old_path_with_namespace)
......
module Geo
class RepositoryDestroyService
attr_reader :id, :name, :path_with_namespace
def initialize(id, name, path)
@id = id
@name = name
@path_with_namespace = path
end
def async_execute
GeoRepositoryDestroyWorker.perform_async(id, name, path_with_namespace)
end
end
end
...@@ -132,10 +132,11 @@ module Gitlab ...@@ -132,10 +132,11 @@ module Gitlab
# GeoRepositoryDestroyWorker to avoid doing this # GeoRepositoryDestroyWorker to avoid doing this
full_path = File.join(deleted_event.repository_storage_path, full_path = File.join(deleted_event.repository_storage_path,
deleted_event.deleted_path) deleted_event.deleted_path)
job_id = ::GeoRepositoryDestroyWorker.perform_async( job_id = ::Geo::RepositoryDestroyService
deleted_event.project_id, .new(deleted_event.project_id,
deleted_event.deleted_project_name, deleted_event.deleted_project_name,
full_path) full_path)
.async_execute
log_event_info(event.created_at, log_event_info(event.created_at,
message: "Deleted project", message: "Deleted project",
project_id: deleted_event.project_id, project_id: deleted_event.project_id,
...@@ -164,8 +165,9 @@ module Gitlab ...@@ -164,8 +165,9 @@ module Gitlab
old_path = renamed_event.old_path_with_namespace old_path = renamed_event.old_path_with_namespace
new_path = renamed_event.new_path_with_namespace new_path = renamed_event.new_path_with_namespace
job_id = ::GeoRepositoryMoveWorker.perform_async( job_id = ::Geo::MoveRepositoryService
renamed_event.project_id, "", old_path, new_path) .new(renamed_event.project_id, "", old_path, new_path)
.async_execute
log_event_info(event.created_at, log_event_info(event.created_at,
message: "Renaming project", message: "Renaming project",
......
...@@ -17,4 +17,18 @@ describe Geo::MoveRepositoryService do ...@@ -17,4 +17,18 @@ describe Geo::MoveRepositoryService do
expect(File.directory?("#{full_new_path}.git")).to be_truthy expect(File.directory?("#{full_new_path}.git")).to be_truthy
end end
end end
describe '#async_execute' do
it 'starts the worker' do
expect(GeoRepositoryMoveWorker).to receive(:perform_async)
subject.async_execute
end
it 'returns job id' do
allow(GeoRepositoryMoveWorker).to receive(:perform_async).and_return('foo')
expect(subject.async_execute).to eq('foo')
end
end
end 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