Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
d4273e2b
Commit
d4273e2b
authored
Feb 10, 2017
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds global minimum mirror sync time option in admin section
parent
904981f7
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
86 additions
and
7 deletions
+86
-7
app/controllers/admin/application_settings_controller.rb
app/controllers/admin/application_settings_controller.rb
+2
-1
app/helpers/mirror_helper.rb
app/helpers/mirror_helper.rb
+6
-0
app/models/application_setting.rb
app/models/application_setting.rb
+17
-1
app/views/admin/application_settings/_form.html.haml
app/views/admin/application_settings/_form.html.haml
+4
-0
app/views/projects/mirrors/show.html.haml
app/views/projects/mirrors/show.html.haml
+2
-2
config/initializers/sidekiq.rb
config/initializers/sidekiq.rb
+4
-3
db/migrate/20170210144005_add_global_minimum_mirror_sync_time_to_application_settings.rb
...lobal_minimum_mirror_sync_time_to_application_settings.rb
+22
-0
db/schema.rb
db/schema.rb
+1
-0
lib/gitlab/mirror.rb
lib/gitlab/mirror.rb
+28
-0
No files found.
app/controllers/admin/application_settings_controller.rb
View file @
d4273e2b
...
...
@@ -166,7 +166,8 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
:elasticsearch_search
,
:repository_size_limit
,
:shared_runners_minutes
,
:usage_ping_enabled
:usage_ping_enabled
,
:minimum_mirror_sync_time
]
end
end
app/helpers/mirror_helper.rb
View file @
d4273e2b
...
...
@@ -4,4 +4,10 @@ module MirrorHelper
message
<<
"<br>To discard the local changes and overwrite the branch with the upstream version, delete it here and choose 'Update Now' above."
if
can?
(
current_user
,
:push_code
,
@project
)
message
end
def
mirror_sync_time_options
Gitlab
::
Mirror
.
sync_time_options
.
select
do
|
key
,
value
|
value
<
current_application_settings
.
minimum_mirror_sync_time
end
end
end
app/models/application_setting.rb
View file @
d4273e2b
...
...
@@ -128,6 +128,10 @@ class ApplicationSetting < ActiveRecord::Base
presence:
true
,
numericality:
{
only_integer:
true
,
greater_than_or_equal_to:
0
}
validates
:minimum_mirror_sync_time
,
presence:
true
,
inclusion:
{
in:
Gitlab
::
Mirror
.
sync_time_options
.
values
}
validates_each
:restricted_visibility_levels
do
|
record
,
attr
,
value
|
value
&
.
each
do
|
level
|
unless
Gitlab
::
VisibilityLevel
.
options
.
has_value?
(
level
)
...
...
@@ -155,6 +159,8 @@ class ApplicationSetting < ActiveRecord::Base
before_save
:ensure_runners_registration_token
before_save
:ensure_health_check_access_token
after_update
:update_mirror_cron_jobs
,
if: :minimum_mirror_sync_time_changed?
after_commit
do
Rails
.
cache
.
write
(
CACHE_KEY
,
self
)
end
...
...
@@ -224,7 +230,8 @@ class ApplicationSetting < ActiveRecord::Base
{
elasticsearch_host:
ENV
[
'ELASTIC_HOST'
]
||
'localhost'
,
elasticsearch_port:
ENV
[
'ELASTIC_PORT'
]
||
'9200'
,
usage_ping_enabled:
true
usage_ping_enabled:
true
,
minimum_mirror_sync_time:
60
}
end
...
...
@@ -236,6 +243,15 @@ class ApplicationSetting < ActiveRecord::Base
create
(
defaults
)
end
def
update_mirror_cron_jobs
Project
.
mirror
.
where
(
'sync_time < ?'
,
minimum_mirror_sync_time
).
update_all
(
sync_time:
minimum_mirror_sync_time
)
RemoteMirror
.
where
(
'sync_time < ?'
,
minimum_mirror_sync_time
).
update_all
(
sync_time:
minimum_mirror_sync_time
)
Gitlab
::
Mirror
.
configure_cron_jobs!
end
def
elasticsearch_host
read_attribute
(
:elasticsearch_host
).
split
(
','
).
map
(
&
:strip
)
end
...
...
app/views/admin/application_settings/_form.html.haml
View file @
d4273e2b
...
...
@@ -71,6 +71,10 @@
%span
.help-block
#repository_size_limit_help_block
Includes LFS objects. It can be overridden per group, or per project. 0 for unlimited.
=
link_to
icon
(
'question-circle'
),
help_page_path
(
"user/admin_area/settings/account_and_limit_settings"
)
.form-group
=
f
.
label
:minimum_mirror_sync_time
,
class:
'control-label col-sm-2'
.col-sm-10
=
f
.
select
:minimum_mirror_sync_time
,
options_for_select
(
Gitlab
::
Mirror
.
sync_time_options
,
@application_setting
.
minimum_mirror_sync_time
),
{},
class:
'form-control'
.form-group
=
f
.
label
:session_expire_delay
,
'Session duration (minutes)'
,
class:
'control-label col-sm-2'
.col-sm-10
...
...
app/views/projects/mirrors/show.html.haml
View file @
d4273e2b
...
...
@@ -47,7 +47,7 @@
=
render
"shared/mirror_trigger_builds_setting"
,
f:
f
.form-group
=
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
(
mirror_
sync_time_options
,
@project
.
sync_time
),
{},
class:
'form-control'
.col-sm-12
%hr
.col-lg-3
...
...
@@ -82,7 +82,7 @@
=
render
"instructions"
.form-group
=
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
(
mirror_
sync_time_options
,
@remote_mirror
.
sync_time
),
{},
class:
'form-control'
.col-sm-12.text-center
%hr
=
f
.
submit
'Save changes'
,
class:
'btn btn-create'
,
name:
'update_remote_mirror'
config/initializers/sidekiq.rb
View file @
d4273e2b
require
'gitlab/current_settings'
include
Gitlab
::
CurrentSettings
# Custom Redis configuration
redis_config_hash
=
Gitlab
::
Redis
.
params
redis_config_hash
[
:namespace
]
=
Gitlab
::
Redis
::
SIDEKIQ_NAMESPACE
...
...
@@ -34,9 +37,7 @@ 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
::
Mirror
.
configure_cron_jobs!
# Gitlab Geo: enable bulk notify job only on primary node
Gitlab
::
Geo
.
bulk_notify_job
.
disable!
unless
Gitlab
::
Geo
.
primary?
...
...
db/migrate/20170210144005_add_global_minimum_mirror_sync_time_to_application_settings.rb
0 → 100644
View file @
d4273e2b
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
AddGlobalMinimumMirrorSyncTimeToApplicationSettings
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_column_with_default
:application_settings
,
:minimum_mirror_sync_time
,
:integer
,
default:
60
,
allow_null:
false
end
def
down
remove_column
:application_settings
,
:minimum_mirror_sync_time
end
end
db/schema.rb
View file @
d4273e2b
...
...
@@ -120,6 +120,7 @@ ActiveRecord::Schema.define(version: 20170211073944) do
t
.
integer
"shared_runners_minutes"
,
default:
0
,
null:
false
t
.
integer
"repository_size_limit"
,
limit:
8
,
default:
0
t
.
integer
"terminal_max_session_time"
,
default:
0
,
null:
false
t
.
integer
"minimum_mirror_sync_time"
,
default:
60
,
null:
false
end
create_table
"approvals"
,
force: :cascade
do
|
t
|
...
...
lib/gitlab/mirror.rb
View file @
d4273e2b
...
...
@@ -6,6 +6,12 @@ module Gitlab
INTERVAL_BEFORE_FIFTEEN
=
14
.
minutes
SYNC_TIME_TO_CRON
=
{
FIFTEEN
=>
"*/15 * * * *"
,
HOURLY
=>
"0 * * * *"
,
DAILY
=>
"0 0 * * *"
}.
freeze
class
<<
self
def
sync_time_options
{
...
...
@@ -23,6 +29,28 @@ module Gitlab
sync_times
end
def
configure_cron_jobs!
minimum_mirror_sync_time
=
current_application_settings
.
minimum_mirror_sync_time
rescue
DAILY
update_all_mirrors_worker_job
=
Sidekiq
::
Cron
::
Job
.
find
(
"update_all_mirrors_worker"
)
update_all_remote_mirrors_worker_job
=
Sidekiq
::
Cron
::
Job
.
find
(
"update_all_remote_mirrors_worker"
)
if
update_all_mirrors_worker
&&
update_all_remote_mirrors_worker
update_all_mirrors_worker
.
destroy
update_all_remote_mirrors_worker
.
destroy
end
Sidekiq
::
Cron
::
Job
.
create
(
name:
'update_all_remote_mirrors_worker'
,
cron:
SYNC_TIME_TO_CRON
[
minimum_mirror_sync_time
],
class:
'UpdateAllRemoteMirrorsWorker'
)
Sidekiq
::
Cron
::
Job
.
create
(
name:
'update_all_mirrors_worker'
,
cron:
SYNC_TIME_TO_CRON
[
minimum_mirror_sync_time
],
class:
'UpdateAllMirrorsWorker'
)
end
def
at_beginning_of_day?
start_at
=
DateTime
.
now
.
at_beginning_of_day
end_at
=
start_at
+
INTERVAL_BEFORE_FIFTEEN
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment