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