Commit 7aed5e9f authored by Tiago Botelho's avatar Tiago Botelho

adds cron job to start running from 15 to 15 minutes and select relevant mirrors to update

parent d02a7171
......@@ -35,7 +35,7 @@ class Project < ActiveRecord::Base
default_value_for :container_registry_enabled, gitlab_config_features.container_registry
default_value_for(:repository_storage) { current_application_settings.pick_repository_storage }
default_value_for(:shared_runners_enabled) { current_application_settings.shared_runners_enabled }
default_value_for (:sync_time) { current_application_settings.default_mirror_sync_time }
default_value_for(:sync_time) { gitlab_config_features.sync_time }
default_value_for :issues_enabled, gitlab_config_features.issues
default_value_for :merge_requests_enabled, gitlab_config_features.merge_requests
default_value_for :builds_enabled, gitlab_config_features.builds
......@@ -218,7 +218,7 @@ class Project < ActiveRecord::Base
validates :sync_time,
presence: true,
inclusion: { in: Gitlab::Mirror.mirror_options.values }
inclusion: { in: Gitlab::Mirror.sync_time_options.values }
with_options if: :mirror? do |project|
project.validates :import_url, presence: true
......
......@@ -47,7 +47,7 @@
= render "shared/mirror_trigger_builds_setting", f: f
.form-group
= f.label :sync_time, "Mirror synchronisation time", class: "label-light append-bottom-0"
= f.select :sync_time, options_for_select(Gitlab::Mirror.mirror_options, @project.sync_time), {}, class: 'form-control'
= f.select :sync_time, options_for_select(Gitlab::Mirror.sync_time_options, @project.sync_time), {}, class: 'form-control'
.col-sm-12
%hr
.col-lg-3
......
......@@ -9,8 +9,8 @@ class UpdateAllMirrorsWorker
fail_stuck_mirrors!
Project.mirror.find_each(batch_size: 200) do |project|
RepositoryUpdateMirrorDispatchWorker.perform_in(rand(30.minutes), project.id)
mirrors_to_sync.find_each(batch_size: 200) do |project|
RepositoryUpdateMirrorDispatchWorker.perform_in(rand(project.sync_time / 2), project.id)
end
end
......@@ -26,6 +26,10 @@ class UpdateAllMirrorsWorker
private
def mirrors_to_sync
Project.where(mirror: true, sync_time: Gitlab::Mirror.sync_times)
end
def try_obtain_lease
# Using 30 minutes timeout based on the 95th percent of timings (currently max of 10 minutes)
lease = ::Gitlab::ExclusiveLease.new("update_all_mirrors", timeout: LEASE_TIMEOUT)
......
......@@ -212,7 +212,7 @@ production: &base
# Update mirrored repositories
update_all_mirrors_worker:
cron: "0 * * * *"
cron: "*/15 * * * *"
# Update remote mirrors
update_all_remote_mirrors_worker:
......
......@@ -223,7 +223,6 @@ Settings['issues_tracker'] ||= {}
Settings['gitlab'] ||= Settingslogic.new({})
Settings.gitlab['default_projects_limit'] ||= 10
Settings.gitlab['default_branch_protection'] ||= 2
Settings.gitlab['default_mirror_sync_time'] ||= 1
Settings.gitlab['default_can_create_group'] = true if Settings.gitlab['default_can_create_group'].nil?
Settings.gitlab['default_theme'] = Gitlab::Themes::APPLICATION_DEFAULT if Settings.gitlab['default_theme'].nil?
Settings.gitlab['host'] ||= ENV['GITLAB_HOST'] || 'localhost'
......@@ -255,6 +254,7 @@ Settings.gitlab['default_projects_features'] ||= {}
Settings.gitlab['webhook_timeout'] ||= 10
Settings.gitlab['max_attachment_size'] ||= 10
Settings.gitlab['session_expire_delay'] ||= 10080
Settings.gitlab.default_projects_features['sync_time'] ||= 60
Settings.gitlab.default_projects_features['issues'] = true if Settings.gitlab.default_projects_features['issues'].nil?
Settings.gitlab.default_projects_features['merge_requests'] = true if Settings.gitlab.default_projects_features['merge_requests'].nil?
Settings.gitlab.default_projects_features['wiki'] = true if Settings.gitlab.default_projects_features['wiki'].nil?
......@@ -372,7 +372,7 @@ Settings.cron_jobs['historical_data_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['historical_data_worker']['cron'] ||= '0 12 * * *'
Settings.cron_jobs['historical_data_worker']['job_class'] = 'HistoricalDataWorker'
Settings.cron_jobs['update_all_mirrors_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['update_all_mirrors_worker']['cron'] ||= '0 * * * *'
Settings.cron_jobs['update_all_mirrors_worker']['cron'] ||= '*/15 * * * *'
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']['cron'] ||= '30 * * * *'
......
module Gitlab
module Mirror
QUARTER = 15
HOUR = 60
DAY = 1440
FIFTEEN = 15
HOURLY = 60
DAYLY = 1440
class << self
def mirror_options
def sync_time_options
{
"Update every 15 minutes": QUARTER,
"Update hourly": HOUR,
"Update every day": DAY,
"Update every 15 minutes" => FIFTEEN,
"Update hourly" => HOURLY,
"Update every day" => DAYLY,
}
end
def to_cron(sync_time)
case sync_time
when QUARTER
"*/15 * * * *"
when HOUR
"0 * * * *"
when DAY
"0 0 * * *"
end
def sync_times
sync_times = [FIFTEEN]
sync_times << DAYLY if at_beginning_of_day?
sync_times << HOURLY if at_beginning_of_hour?
return sync_times
end
def at_beginning_of_day?
beginning_of_day = DateTime.now.at_beginning_of_day
DateTime.now >= beginning_of_day && DateTime.now <= beginning_of_day + 14.minutes
end
def at_beginning_of_hour?
beginning_of_hour = DateTime.now.at_beginning_of_hour
DateTime.now >= beginning_of_hour && DateTime.now <= beginning_of_hour + 14.minutes
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