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 ...@@ -29,6 +29,6 @@ class GeoNode < ActiveRecord::Base
end end
def notify_url def notify_url
# TODO: Notification endpoint URI::join(uri, '/api/geo/refresh_projects').to_s
end end
end end
require_relative 'base_service'
module Geo module Geo
class EnqueueUpdateService < BaseService class EnqueueUpdateService < Geo::BaseService
attr_reader :project attr_reader :project
def initialize(project) def initialize(project)
......
require_relative 'base_service'
module Geo module Geo
class NotifyNodesService < BaseService class NotifyNodesService < Geo::BaseService
include HTTParty include HTTParty
BATCH_SIZE = 250 BATCH_SIZE = 250
...@@ -37,10 +35,10 @@ module Geo ...@@ -37,10 +35,10 @@ module Geo
def notify_updated_projects(node, projects) def notify_updated_projects(node, projects)
self.post(node.notify_url, self.post(node.notify_url,
body: projects.to_json, body: { projects: projects }.to_json,
headers: { headers: {
"Content-Type" => "application/json", 'Content-Type' => 'application/json',
"X-Gitlab-Geo-Event" => "Update Repositories" 'X-Gitlab-Geo-Event' => 'Update Repositories'
}) })
# TODO: Authentication # TODO: Authentication
......
class ScheduleRepoUpdateService module Geo
attr_reader :projects class ScheduleRepoUpdateService
attr_reader :projects
def initialize(projects) def initialize(projects)
@projects = projects @projects = projects
end end
def execute def execute
@projects.each do |project_id| @projects.each do |project_id|
# TODO: async repository fetch GeoRepositoryUpdateWorker.perform_async(project_id)
end
end end
end end
end end
...@@ -9,7 +9,14 @@ class GeoRepositoryUpdateWorker ...@@ -9,7 +9,14 @@ class GeoRepositoryUpdateWorker
def perform(project_id) def perform(project_id)
@project = Project.find(project_id) @project = Project.find(project_id)
fetch_repository(@project.repository, @project.url_to_repo)
# @current_user = @project.mirror_user || @project.creator # @current_user = @project.mirror_user || @project.creator
# Projects::UpdateMirrorService.new(@project, @current_user).execute # Projects::UpdateMirrorService.new(@project, @current_user).execute
end end
private
def fetch_repository(repository, remote_url)
repository.fetch_upstream(remote_url)
end
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