Commit 45b39f6b authored by Gabriel Mazetto's avatar Gabriel Mazetto

WIP: Batched notify and endpoint for Gitlab Geo

parent c7b28a64
......@@ -29,6 +29,6 @@ class GeoNode < ActiveRecord::Base
end
def notify_url
# TODO: Notification endpoint
URI::join(uri, '/api/geo/refresh_projects').to_s
end
end
require_relative 'base_service'
module Geo
class EnqueueUpdateService < BaseService
class EnqueueUpdateService < Geo::BaseService
attr_reader :project
def initialize(project)
......
require_relative 'base_service'
module Geo
class NotifyNodesService < BaseService
class NotifyNodesService < Geo::BaseService
include HTTParty
BATCH_SIZE = 250
......@@ -37,10 +35,10 @@ module Geo
def notify_updated_projects(node, projects)
self.post(node.notify_url,
body: projects.to_json,
body: { projects: projects }.to_json,
headers: {
"Content-Type" => "application/json",
"X-Gitlab-Geo-Event" => "Update Repositories"
'Content-Type' => 'application/json',
'X-Gitlab-Geo-Event' => 'Update Repositories'
})
# TODO: Authentication
......
class ScheduleRepoUpdateService
attr_reader :projects
module Geo
class ScheduleRepoUpdateService
attr_reader :projects
def initialize(projects)
@projects = projects
end
def initialize(projects)
@projects = projects
end
def execute
@projects.each do |project_id|
# TODO: async repository fetch
def execute
@projects.each do |project_id|
GeoRepositoryUpdateWorker.perform_async(project_id)
end
end
end
end
......@@ -9,7 +9,14 @@ class GeoRepositoryUpdateWorker
def perform(project_id)
@project = Project.find(project_id)
fetch_repository(@project.repository, @project.url_to_repo)
# @current_user = @project.mirror_user || @project.creator
# Projects::UpdateMirrorService.new(@project, @current_user).execute
end
private
def fetch_repository(repository, remote_url)
repository.fetch_upstream(remote_url)
end
end
module API
class Geo < Grape::API
before { authenticated_as_admin! }
resource :geo do
# Enqueue a batch of IDs of modified projects to have their
# repositories updated
#
# Example request:
# POST /refresh_projects
post 'refresh_projects' do
attrs = attributes_for_keys [:projects]
Geo::ScheduleRepoUpdateService.new(attrs[:projects]).execute
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