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