Commit 2547f41f authored by Gabriel Mazetto's avatar Gabriel Mazetto

code for Bulk Notification of enqueued wiki changes

parent 47d4ede2
...@@ -52,10 +52,14 @@ class GeoNode < ActiveRecord::Base ...@@ -52,10 +52,14 @@ class GeoNode < ActiveRecord::Base
self.relative_url_root = new_uri.path != '/' ? new_uri.path : '' self.relative_url_root = new_uri.path != '/' ? new_uri.path : ''
end end
def notify_url def notify_projects_url
URI.join(uri, "#{uri.path}/", "api/#{API::API.version}/geo/refresh_projects").to_s URI.join(uri, "#{uri.path}/", "api/#{API::API.version}/geo/refresh_projects").to_s
end end
def notify_wikis_url
URI.join(uri, "#{uri.path}/", "api/#{API::API.version}/geo/refresh_wikis").to_s
end
def oauth_callback_url def oauth_callback_url
URI.join(uri, "#{uri.path}/", 'oauth/geo/callback').to_s URI.join(uri, "#{uri.path}/", 'oauth/geo/callback').to_s
end end
......
...@@ -6,26 +6,33 @@ module Geo ...@@ -6,26 +6,33 @@ module Geo
default_timeout Gitlab.config.gitlab.webhook_timeout default_timeout Gitlab.config.gitlab.webhook_timeout
def initialize def initialize
@queue = Gitlab::Geo::UpdateQueue.new('updated_projects') @proj_queue = Gitlab::Geo::UpdateQueue.new('updated_projects')
@wiki_queue = Gitlab::Geo::UpdateQueue.new('updated_wikis')
end end
def execute def execute
return if @queue.empty? process(@proj_queue, :notify_projects_url)
projects = @queue.fetch_batched_data process(@wiki_queue, :notify_wikis_url)
end
private
def process(queue, notify_url_method)
return if queue.empty?
projects = queue.fetch_batched_data
::Gitlab::Geo.secondary_nodes.each do |node| ::Gitlab::Geo.secondary_nodes.each do |node|
success, message = notify_updated_projects(node, projects) notify_url = node.send(notify_url_method.to_sym)
success, message = notify(notify_url, projects)
unless success unless success
Rails.logger.error("GitLab failed to notify #{node.url} : #{message}") Rails.logger.error("GitLab failed to notify #{node.url} to #{notify_url} : #{message}")
@queue.store_batched_data(projects) queue.store_batched_data(projects)
end end
end end
end end
private def notify(notify_url, projects)
response = self.class.post(notify_url,
def notify_updated_projects(node, projects)
response = self.class.post(node.notify_url,
body: { projects: projects }.to_json, body: { projects: projects }.to_json,
headers: { headers: {
'Content-Type' => 'application/json', 'Content-Type' => 'application/json',
......
...@@ -147,14 +147,21 @@ describe GeoNode, type: :model do ...@@ -147,14 +147,21 @@ describe GeoNode, type: :model do
end end
end end
describe '#notify_url' do describe '#notify_projects_url' do
let(:refresh_url) { 'https://localhost:3000/gitlab/api/v3/geo/refresh_projects' } let(:refresh_url) { 'https://localhost:3000/gitlab/api/v3/geo/refresh_projects' }
it 'returns api url based on node uri' do it 'returns api url based on node uri' do
expect(new_node.notify_url).to eq(refresh_url) expect(new_node.notify_projects_url).to eq(refresh_url)
end end
end end
describe '#notify_wikis_url' do
let(:refresh_url) { 'https://localhost:3000/gitlab/api/v3/geo/refresh_wikis' }
it 'returns api url based on node uri' do
expect(new_node.notify_wikis_url).to eq(refresh_url)
end
end
describe '#oauth_callback_url' do describe '#oauth_callback_url' do
let(:oauth_callback_url) { 'https://localhost:3000/gitlab/oauth/geo/callback' } let(:oauth_callback_url) { 'https://localhost:3000/gitlab/oauth/geo/callback' }
......
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