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
include AfterCommitQueue
include Gitlab::ConfigHelper
include Gitlab::CurrentSettings
extend Gitlab::ConfigHelper
attr_encrypted :credentials,
key: Gitlab::Application.secrets.db_key_base,
......
......@@ -46,7 +46,7 @@
- if @project.builds_enabled?
= render "shared/mirror_trigger_builds_setting", f: f
.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'
.col-sm-12
%hr
......@@ -81,7 +81,7 @@
= rm_form.text_field :url, class: "form-control", placeholder: 'https://username:password@gitlab.company.com/group/project.git'
= render "instructions"
.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'
.col-sm-12.text-center
%hr
......
......@@ -2,7 +2,7 @@ class UpdateAllMirrorsWorker
include Sidekiq::Worker
include CronjobQueue
LEASE_TIMEOUT = 3600
LEASE_TIMEOUT = 840
def perform
return unless try_obtain_lease
......@@ -27,11 +27,10 @@ class UpdateAllMirrorsWorker
private
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
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.try_obtain
end
......
......@@ -17,6 +17,6 @@ class UpdateAllRemoteMirrorsWorker
private
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
......@@ -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']['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'] ||= '*/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']['cron'] ||= '30 1 * * *'
Settings.cron_jobs['ldap_sync_worker']['job_class'] = 'LdapSyncWorker'
......
......@@ -34,6 +34,10 @@ Sidekiq.configure_server do |config|
end
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.bulk_notify_job.disable! unless Gitlab::Geo.primary?
......
......@@ -2,7 +2,7 @@ module Gitlab
module Mirror
FIFTEEN = 15
HOURLY = 60
DAYLY = 1440
DAILY = 1440
INTERVAL_BEFORE_FIFTEEN = 14.minutes
......@@ -11,13 +11,13 @@ module Gitlab
{
"Update every 15 minutes" => FIFTEEN,
"Update hourly" => HOURLY,
"Update every day" => DAYLY,
"Update every day" => DAILY,
}
end
def sync_times
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
......
require 'spec_helper'
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
context 'when the current project is a mirror' do
......
......@@ -7,15 +7,15 @@ describe UpdateAllMirrorsWorker do
end
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_day => 3
}
let!(:mirror1) { create(:empty_project, :mirror, sync_time: Gitlab::Mirror::FIFTEEN) }
let!(:mirror2) { create(:empty_project, :mirror, sync_time: Gitlab::Mirror::HOURLY) }
let!(:mirror3) { create(:empty_project, :mirror, sync_time: Gitlab::Mirror::DAYLY) }
let(:mirrors) { Project.where(mirror: true, sync_time: Gitlab::Mirror.sync_times) }
let!(:mirror3) { create(:empty_project, :mirror, sync_time: Gitlab::Mirror::DAILY) }
let(:mirrors) { Project.mirror.where(sync_time: Gitlab::Mirror.sync_times) }
it 'fails stuck mirrors' do
worker = described_class.new
......@@ -25,7 +25,7 @@ describe UpdateAllMirrorsWorker do
worker.perform
end
PROJECT_COUNT_WITH_TIME.each do |time, project_count|
project_count_with_time.each do |time, project_count|
describe "at #{time}" do
before do
allow(DateTime).to receive(:now).and_return(time)
......
......@@ -2,14 +2,14 @@ require 'rails_helper'
describe UpdateAllRemoteMirrorsWorker 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_day => 3
}
let!(:mirror1) { create(:project, :remote_mirror, sync_time: Gitlab::Mirror::FIFTEEN) }
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) }
it 'fails stuck mirrors' do
......@@ -20,7 +20,7 @@ describe UpdateAllRemoteMirrorsWorker do
worker.perform
end
PROJECT_COUNT_WITH_TIME.each do |time, project_count|
project_count_with_time.each do |time, project_count|
describe "at #{time}" do
before do
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