Commit d02a7171 authored by Tiago Botelho's avatar Tiago Botelho

adds select field and sync time migration for mirror sync cron jobs

parent 5b49fc34
......@@ -46,7 +46,8 @@ class Projects::MirrorsController < Projects::ApplicationController
end
def mirror_params
params.require(:project).permit(:mirror, :import_url, :mirror_user_id, :mirror_trigger_builds,
remote_mirrors_attributes: [:url, :id, :enabled])
params.require(:project).permit(:mirror, :import_url, :mirror_user_id,
:mirror_trigger_builds, :sync_time,
remote_mirrors_attributes: [:url, :id, :enabled])
end
end
......@@ -35,6 +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 :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
......@@ -215,6 +216,10 @@ class Project < ActiveRecord::Base
validates :repository_size_limit,
numericality: { only_integer: true, greater_than_or_equal_to: 0, allow_nil: true }
validates :sync_time,
presence: true,
inclusion: { in: Gitlab::Mirror.mirror_options.values }
with_options if: :mirror? do |project|
project.validates :import_url, presence: true
project.validates :mirror_user, presence: true
......
......@@ -45,6 +45,9 @@
They need to have at least master access to this project.
- if @project.builds_enabled?
= 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'
.col-sm-12
%hr
.col-lg-3
......
......@@ -223,6 +223,7 @@ 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'
......
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddSyncScheduleToProjects < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
disable_ddl_transaction!
def up
add_column_with_default :projects, :sync_time, :integer, default: 60
end
def down
remove_column :projects, :sync_time
end
end
......@@ -1112,6 +1112,7 @@ ActiveRecord::Schema.define(version: 20170204181513) do
t.text "description_html"
t.boolean "only_allow_merge_if_all_discussions_are_resolved"
t.integer "repository_size_limit", limit: 8
t.integer "sync_time", default: 60, null: false
end
add_index "projects", ["ci_id"], name: "index_projects_on_ci_id", using: :btree
......
module Gitlab
module Mirror
QUARTER = 15
HOUR = 60
DAY = 1440
class << self
def mirror_options
{
"Update every 15 minutes": QUARTER,
"Update hourly": HOUR,
"Update every day": DAY,
}
end
def to_cron(sync_time)
case sync_time
when QUARTER
"*/15 * * * *"
when HOUR
"0 * * * *"
when DAY
"0 0 * * *"
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