Commit af037c0c authored by Douwe Maan's avatar Douwe Maan

Merge branch '1071-geo-replicate-repository-creation' into 'master'

Replicate repository creation in Geo secondary node

Closes #1071

See merge request !952
parents 32b88789 45b2d0f6
module Geo
class ScheduleRepoCreateService
attr_reader :id
def initialize(params)
@id = params['project_id']
end
def execute
GeoRepositoryCreateWorker.perform_async(id)
end
end
end
class GeoRepositoryCreateWorker
include Sidekiq::Worker
include GeoQueue
def perform(id)
project = Project.find(id)
project.ensure_dir_exist
project.create_repository unless project.repository_exists? || project.import?
end
end
---
title: 'Geo: Replicate repository creation in Geo secondary node'
merge_request: 952
author:
...@@ -33,6 +33,9 @@ module API ...@@ -33,6 +33,9 @@ module API
when 'tag_push' when 'tag_push'
required_attributes! %w(event_name project_id project) required_attributes! %w(event_name project_id project)
::Geo::ScheduleWikiRepoUpdateService.new(params).execute ::Geo::ScheduleWikiRepoUpdateService.new(params).execute
when 'project_create'
required_attributes! %w(event_name project_id)
::Geo::ScheduleRepoCreateService.new(params).execute
when 'project_destroy' when 'project_destroy'
required_attributes! %w(event_name project_id path_with_namespace) required_attributes! %w(event_name project_id path_with_namespace)
::Geo::ScheduleRepoDestroyService.new(params).execute ::Geo::ScheduleRepoDestroyService.new(params).execute
......
require 'spec_helper'
describe Geo::ScheduleRepoCreateService, services: true do
let(:project) { create(:project) }
subject { described_class.new(project_id: project.id) }
describe '#execute' do
it 'schedules the repository creation' do
Sidekiq::Worker.clear_all
Sidekiq::Testing.fake! do
expect{ subject.execute }.to change(GeoRepositoryCreateWorker.jobs, :size).by(1)
end
end
end
end
require 'spec_helper'
describe GeoRepositoryCreateWorker do
let(:user) { create :user }
let(:project) { create :project }
let(:perform!) { subject.perform(project.id) }
before { expect(Project).to receive(:find).at_least(:once).with(project.id) { project } }
context 'when no repository' do
before { expect(project).to receive(:repository_exists?) { false } }
it 'creates the repository' do
expect(project).to receive(:create_repository)
perform!
end
it 'does not create the repository when its being imported' do
expect(project).to receive(:import?) { true }
expect(project).not_to receive(:create_repository)
perform!
end
end
context 'when repository exists' do
before { expect(project).to receive(:repository_exists?) { true } }
it 'does not try to create the repository again' do
expect(project).not_to receive(:create_repository)
perform!
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