Commit 4c50e915 authored by Tiago Botelho's avatar Tiago Botelho

applies changes to gitlab settings and gitlab yaml file

parent 24cb7c63
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,
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
- if @project.builds_enabled? - if @project.builds_enabled?
= render "shared/mirror_trigger_builds_setting", f: f = render "shared/mirror_trigger_builds_setting", f: f
.form-group .form-group
= f.label :sync_time, "Synchronisation time", class: "label-light append-bottom-0" = f.label :sync_time, "Synchronization time", class: "label-light append-bottom-0"
= f.select :sync_time, options_for_select(Gitlab::Mirror.sync_time_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
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
= 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 .form-group
= rm_form.label :sync_time, "Synchronisation time", class: "label-light append-bottom-0" = rm_form.label :sync_time, "Synchronization time", class: "label-light append-bottom-0"
= rm_form.select :sync_time, options_for_select(Gitlab::Mirror.sync_time_options, @remote_mirror.sync_time), {}, class: 'form-control' = rm_form.select :sync_time, options_for_select(Gitlab::Mirror.sync_time_options, @remote_mirror.sync_time), {}, class: 'form-control'
.col-sm-12.text-center .col-sm-12.text-center
%hr %hr
......
...@@ -2,7 +2,7 @@ class UpdateAllMirrorsWorker ...@@ -2,7 +2,7 @@ class UpdateAllMirrorsWorker
include Sidekiq::Worker include Sidekiq::Worker
include CronjobQueue include CronjobQueue
LEASE_TIMEOUT = 3600 LEASE_TIMEOUT = 840
def perform def perform
return unless try_obtain_lease return unless try_obtain_lease
...@@ -27,11 +27,10 @@ class UpdateAllMirrorsWorker ...@@ -27,11 +27,10 @@ class UpdateAllMirrorsWorker
private private
def mirrors_to_sync def mirrors_to_sync
Project.mirror.where(sync_time: Gitlab::Mirror.sync_times) Project.mirror.where("NOW() >= mirror_last_update_at + sync_time * interval '1 minute' OR sync_time IN (?)", Gitlab::Mirror.sync_times)
end 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)
lease = ::Gitlab::ExclusiveLease.new("update_all_mirrors", timeout: LEASE_TIMEOUT) lease = ::Gitlab::ExclusiveLease.new("update_all_mirrors", timeout: LEASE_TIMEOUT)
lease.try_obtain lease.try_obtain
end end
......
...@@ -17,6 +17,6 @@ class UpdateAllRemoteMirrorsWorker ...@@ -17,6 +17,6 @@ class UpdateAllRemoteMirrorsWorker
private private
def remote_mirrors_to_sync def remote_mirrors_to_sync
RemoteMirror.where(sync_time: Gitlab::Mirror.sync_times) RemoteMirror.where("NOW() >= updated_at + sync_time * interval '1 minute' OR sync_time IN (?)", Gitlab::Mirror.sync_times)
end end
end end
...@@ -370,12 +370,6 @@ Settings.cron_jobs['repository_archive_cache_worker']['job_class'] = 'Repository ...@@ -370,12 +370,6 @@ Settings.cron_jobs['repository_archive_cache_worker']['job_class'] = 'Repository
Settings.cron_jobs['historical_data_worker'] ||= Settingslogic.new({}) 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']['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'] ||= '*/15 * * * *'
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 * * *'
Settings.cron_jobs['ldap_sync_worker']['job_class'] = 'LdapSyncWorker' Settings.cron_jobs['ldap_sync_worker']['job_class'] = 'LdapSyncWorker'
......
...@@ -34,6 +34,10 @@ Sidekiq.configure_server do |config| ...@@ -34,6 +34,10 @@ Sidekiq.configure_server do |config|
end end
Sidekiq::Cron::Job.load_from_hash! cron_jobs Sidekiq::Cron::Job.load_from_hash! cron_jobs
# These jobs should not be allowed to be configured in gitlab.yml
Sidekiq::Cron::Job.create(name: 'update_all_remote_mirrors_worker', cron: '*/15 * * * *', class: 'UpdateAllRemoteMirrorsWorker')
Sidekiq::Cron::Job.create(name: 'update_all_mirrors_worker', cron: '*/15 * * * *', class: 'UpdateAllMirrorsWorker')
# Gitlab Geo: enable bulk notify job only on primary node # Gitlab Geo: enable bulk notify job only on primary node
Gitlab::Geo.bulk_notify_job.disable! unless Gitlab::Geo.primary? Gitlab::Geo.bulk_notify_job.disable! unless Gitlab::Geo.primary?
......
...@@ -2,7 +2,7 @@ module Gitlab ...@@ -2,7 +2,7 @@ module Gitlab
module Mirror module Mirror
FIFTEEN = 15 FIFTEEN = 15
HOURLY = 60 HOURLY = 60
DAYLY = 1440 DAILY = 1440
INTERVAL_BEFORE_FIFTEEN = 14.minutes INTERVAL_BEFORE_FIFTEEN = 14.minutes
...@@ -11,13 +11,13 @@ module Gitlab ...@@ -11,13 +11,13 @@ module Gitlab
{ {
"Update every 15 minutes" => FIFTEEN, "Update every 15 minutes" => FIFTEEN,
"Update hourly" => HOURLY, "Update hourly" => HOURLY,
"Update every day" => DAYLY, "Update every day" => DAILY,
} }
end end
def sync_times def sync_times
sync_times = [FIFTEEN] sync_times = [FIFTEEN]
sync_times << DAYLY if at_beginning_of_day? sync_times << DAILY if at_beginning_of_day?
sync_times << HOURLY if at_beginning_of_hour? sync_times << HOURLY if at_beginning_of_hour?
sync_times sync_times
......
require 'spec_helper' require 'spec_helper'
describe Projects::MirrorsController do describe Projects::MirrorsController do
let(:sync_times) { [Gitlab::Mirror::FIFTEEN, Gitlab::Mirror::HOURLY, Gitlab::Mirror::DAYLY] } let(:sync_times) { Gitlab::Mirror.sync_time_options.values }
describe 'setting up a mirror' do describe 'setting up a mirror' do
context 'when the current project is a mirror' do context 'when the current project is a mirror' do
......
...@@ -7,15 +7,15 @@ describe UpdateAllMirrorsWorker do ...@@ -7,15 +7,15 @@ describe UpdateAllMirrorsWorker do
end end
describe '#perform' do describe '#perform' do
PROJECT_COUNT_WITH_TIME = { DateTime.now.beginning_of_hour + 15.minutes => 1, project_count_with_time = { DateTime.now.beginning_of_hour + 15.minutes => 1,
DateTime.now.beginning_of_hour => 2, DateTime.now.beginning_of_hour => 2,
DateTime.now.beginning_of_day => 3 DateTime.now.beginning_of_day => 3
} }
let!(:mirror1) { create(:empty_project, :mirror, sync_time: Gitlab::Mirror::FIFTEEN) } let!(:mirror1) { create(:empty_project, :mirror, sync_time: Gitlab::Mirror::FIFTEEN) }
let!(:mirror2) { create(:empty_project, :mirror, sync_time: Gitlab::Mirror::HOURLY) } let!(:mirror2) { create(:empty_project, :mirror, sync_time: Gitlab::Mirror::HOURLY) }
let!(:mirror3) { create(:empty_project, :mirror, sync_time: Gitlab::Mirror::DAYLY) } let!(:mirror3) { create(:empty_project, :mirror, sync_time: Gitlab::Mirror::DAILY) }
let(:mirrors) { Project.where(mirror: true, sync_time: Gitlab::Mirror.sync_times) } let(:mirrors) { Project.mirror.where(sync_time: Gitlab::Mirror.sync_times) }
it 'fails stuck mirrors' do it 'fails stuck mirrors' do
worker = described_class.new worker = described_class.new
...@@ -25,7 +25,7 @@ describe UpdateAllMirrorsWorker do ...@@ -25,7 +25,7 @@ describe UpdateAllMirrorsWorker do
worker.perform worker.perform
end end
PROJECT_COUNT_WITH_TIME.each do |time, project_count| project_count_with_time.each do |time, project_count|
describe "at #{time}" do describe "at #{time}" do
before do before do
allow(DateTime).to receive(:now).and_return(time) allow(DateTime).to receive(:now).and_return(time)
......
...@@ -2,14 +2,14 @@ require 'rails_helper' ...@@ -2,14 +2,14 @@ require 'rails_helper'
describe UpdateAllRemoteMirrorsWorker do describe UpdateAllRemoteMirrorsWorker do
describe "#perform" do describe "#perform" do
PROJECT_COUNT_WITH_TIME = { DateTime.now.beginning_of_hour + 15.minutes => 1, project_count_with_time = { DateTime.now.beginning_of_hour + 15.minutes => 1,
DateTime.now.beginning_of_hour => 2, DateTime.now.beginning_of_hour => 2,
DateTime.now.beginning_of_day => 3 DateTime.now.beginning_of_day => 3
} }
let!(:mirror1) { create(:project, :remote_mirror, sync_time: Gitlab::Mirror::FIFTEEN) } let!(:mirror1) { create(:project, :remote_mirror, sync_time: Gitlab::Mirror::FIFTEEN) }
let!(:mirror2) { create(:project, :remote_mirror, sync_time: Gitlab::Mirror::HOURLY) } let!(:mirror2) { create(:project, :remote_mirror, sync_time: Gitlab::Mirror::HOURLY) }
let!(:mirror3) { create(:project, :remote_mirror, sync_time: Gitlab::Mirror::DAYLY) } let!(:mirror3) { create(:project, :remote_mirror, sync_time: Gitlab::Mirror::DAILY) }
let(:mirrors) { RemoteMirror.where(sync_time: Gitlab::Mirror.sync_times) } let(:mirrors) { RemoteMirror.where(sync_time: Gitlab::Mirror.sync_times) }
it 'fails stuck mirrors' do it 'fails stuck mirrors' do
...@@ -20,7 +20,7 @@ describe UpdateAllRemoteMirrorsWorker do ...@@ -20,7 +20,7 @@ describe UpdateAllRemoteMirrorsWorker do
worker.perform worker.perform
end end
PROJECT_COUNT_WITH_TIME.each do |time, project_count| project_count_with_time.each do |time, project_count|
describe "at #{time}" do describe "at #{time}" do
before do before do
allow(DateTime).to receive(:now).and_return(time) allow(DateTime).to receive(:now).and_return(time)
......
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