Commit 0cd84ba4 authored by Tiago Botelho's avatar Tiago Botelho

adds remote sync time feature

parent 7aed5e9f
...@@ -48,6 +48,6 @@ class Projects::MirrorsController < Projects::ApplicationController ...@@ -48,6 +48,6 @@ class Projects::MirrorsController < Projects::ApplicationController
def mirror_params def mirror_params
params.require(:project).permit(:mirror, :import_url, :mirror_user_id, params.require(:project).permit(:mirror, :import_url, :mirror_user_id,
:mirror_trigger_builds, :sync_time, :mirror_trigger_builds, :sync_time,
remote_mirrors_attributes: [:url, :id, :enabled]) remote_mirrors_attributes: [:url, :id, :enabled, :remote_sync_time])
end end
end end
class RemoteMirror < ActiveRecord::Base class RemoteMirror < ActiveRecord::Base
include AfterCommitQueue include AfterCommitQueue
include Gitlab::ConfigHelper
include Gitlab::CurrentSettings
extend Gitlab::ConfigHelper
attr_encrypted :credentials, attr_encrypted :credentials,
key: Gitlab::Application.secrets.db_key_base, key: Gitlab::Application.secrets.db_key_base,
...@@ -11,7 +15,11 @@ class RemoteMirror < ActiveRecord::Base ...@@ -11,7 +15,11 @@ class RemoteMirror < ActiveRecord::Base
belongs_to :project, inverse_of: :remote_mirrors belongs_to :project, inverse_of: :remote_mirrors
default_value_for :remote_sync_time, gitlab_config_features.sync_time
validates :url, presence: true, url: { protocols: %w(ssh git http https), allow_blank: true } validates :url, presence: true, url: { protocols: %w(ssh git http https), allow_blank: true }
validates :remote_sync_time, presence: true,
inclusion: { in: Gitlab::Mirror.sync_time_options.values }
validate :url_availability, if: -> (mirror) { mirror.url_changed? || mirror.enabled? } validate :url_availability, if: -> (mirror) { mirror.url_changed? || mirror.enabled? }
after_save :refresh_remote, if: :mirror_url_changed? after_save :refresh_remote, if: :mirror_url_changed?
......
...@@ -80,6 +80,9 @@ ...@@ -80,6 +80,9 @@
= rm_form.label :url, "Git repository URL", class: "label-light" = rm_form.label :url, "Git repository URL", class: "label-light"
= rm_form.text_field :url, class: "form-control", placeholder: 'https://username:password@gitlab.company.com/group/project.git' = rm_form.text_field :url, class: "form-control", placeholder: 'https://username:password@gitlab.company.com/group/project.git'
= render "instructions" = render "instructions"
.form-group
= rm_form.label :remote_sync_time, "Remote Mirror synchronisation time", class: "label-light append-bottom-0"
= rm_form.select :remote_sync_time, options_for_select(Gitlab::Mirror.sync_time_options, @remote_mirror.remote_sync_time), {}, class: 'form-control'
.col-sm-12.text-center .col-sm-12.text-center
%hr %hr
= f.submit 'Save changes', class: 'btn btn-create', name: 'update_remote_mirror' = f.submit 'Save changes', class: 'btn btn-create', name: 'update_remote_mirror'
...@@ -5,7 +5,7 @@ class UpdateAllRemoteMirrorsWorker ...@@ -5,7 +5,7 @@ class UpdateAllRemoteMirrorsWorker
def perform def perform
fail_stuck_mirrors! fail_stuck_mirrors!
RemoteMirror.find_each(batch_size: 50).each(&:sync) remote_mirrors_to_sync.find_each(batch_size: 50).each(&:sync)
end end
def fail_stuck_mirrors! def fail_stuck_mirrors!
...@@ -13,4 +13,10 @@ class UpdateAllRemoteMirrorsWorker ...@@ -13,4 +13,10 @@ class UpdateAllRemoteMirrorsWorker
remote_mirror.mark_as_failed('The mirror update took too long to complete.') remote_mirror.mark_as_failed('The mirror update took too long to complete.')
end end
end end
private
def remote_mirrors_to_sync
RemoteMirror.where(remote_sync_time: Gitlab::Mirror.sync_times)
end
end end
...@@ -210,14 +210,6 @@ production: &base ...@@ -210,14 +210,6 @@ production: &base
historical_data_worker: historical_data_worker:
cron: "0 12 * * *" cron: "0 12 * * *"
# Update mirrored repositories
update_all_mirrors_worker:
cron: "*/15 * * * *"
# Update remote mirrors
update_all_remote_mirrors_worker:
cron: "30 * * * *"
# In addition to refreshing users when they log in, # In addition to refreshing users when they log in,
# periodically refresh LDAP users membership. # periodically refresh LDAP users membership.
# NOTE: This will only take effect if LDAP is enabled # NOTE: This will only take effect if LDAP is enabled
......
...@@ -375,7 +375,7 @@ Settings.cron_jobs['update_all_mirrors_worker'] ||= Settingslogic.new({}) ...@@ -375,7 +375,7 @@ Settings.cron_jobs['update_all_mirrors_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['update_all_mirrors_worker']['cron'] ||= '*/15 * * * *' Settings.cron_jobs['update_all_mirrors_worker']['cron'] ||= '*/15 * * * *'
Settings.cron_jobs['update_all_mirrors_worker']['job_class'] = 'UpdateAllMirrorsWorker' Settings.cron_jobs['update_all_mirrors_worker']['job_class'] = 'UpdateAllMirrorsWorker'
Settings.cron_jobs['update_all_remote_mirrors_worker'] ||= Settingslogic.new({}) Settings.cron_jobs['update_all_remote_mirrors_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['update_all_remote_mirrors_worker']['cron'] ||= '30 * * * *' Settings.cron_jobs['update_all_remote_mirrors_worker']['cron'] ||= '*/15 * * * *'
Settings.cron_jobs['update_all_remote_mirrors_worker']['job_class'] = 'UpdateAllRemoteMirrorsWorker' Settings.cron_jobs['update_all_remote_mirrors_worker']['job_class'] = 'UpdateAllRemoteMirrorsWorker'
Settings.cron_jobs['ldap_sync_worker'] ||= Settingslogic.new({}) Settings.cron_jobs['ldap_sync_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['ldap_sync_worker']['cron'] ||= '30 1 * * *' Settings.cron_jobs['ldap_sync_worker']['cron'] ||= '30 1 * * *'
......
...@@ -1206,6 +1206,7 @@ ActiveRecord::Schema.define(version: 20170204181513) do ...@@ -1206,6 +1206,7 @@ ActiveRecord::Schema.define(version: 20170204181513) do
t.string "encrypted_credentials_salt" t.string "encrypted_credentials_salt"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "remote_sync_time", default: 60, null: false
end end
add_index "remote_mirrors", ["project_id"], name: "index_remote_mirrors_on_project_id", using: :btree add_index "remote_mirrors", ["project_id"], name: "index_remote_mirrors_on_project_id", using: :btree
......
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