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
7aed5e9f
Commit
7aed5e9f
authored
Jan 26, 2017
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds cron job to start running from 15 to 15 minutes and select relevant mirrors to update
parent
d02a7171
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
24 deletions
+35
-24
app/models/project.rb
app/models/project.rb
+2
-2
app/views/projects/mirrors/show.html.haml
app/views/projects/mirrors/show.html.haml
+1
-1
app/workers/update_all_mirrors_worker.rb
app/workers/update_all_mirrors_worker.rb
+6
-2
config/gitlab.yml.example
config/gitlab.yml.example
+1
-1
config/initializers/1_settings.rb
config/initializers/1_settings.rb
+2
-2
lib/gitlab/mirror.rb
lib/gitlab/mirror.rb
+23
-16
No files found.
app/models/project.rb
View file @
7aed5e9f
...
...
@@ -35,7 +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
(
:sync_time
)
{
gitlab_config_features
.
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
...
...
@@ -218,7 +218,7 @@ class Project < ActiveRecord::Base
validates
:sync_time
,
presence:
true
,
inclusion:
{
in:
Gitlab
::
Mirror
.
mirror
_options
.
values
}
inclusion:
{
in:
Gitlab
::
Mirror
.
sync_time
_options
.
values
}
with_options
if: :mirror?
do
|
project
|
project
.
validates
:import_url
,
presence:
true
...
...
app/views/projects/mirrors/show.html.haml
View file @
7aed5e9f
...
...
@@ -47,7 +47,7 @@
=
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'
=
f
.
select
:sync_time
,
options_for_select
(
Gitlab
::
Mirror
.
sync_time
_options
,
@project
.
sync_time
),
{},
class:
'form-control'
.col-sm-12
%hr
.col-lg-3
...
...
app/workers/update_all_mirrors_worker.rb
View file @
7aed5e9f
...
...
@@ -9,8 +9,8 @@ class UpdateAllMirrorsWorker
fail_stuck_mirrors!
Project
.
mirror
.
find_each
(
batch_size:
200
)
do
|
project
|
RepositoryUpdateMirrorDispatchWorker
.
perform_in
(
rand
(
30
.
minutes
),
project
.
id
)
mirrors_to_sync
.
find_each
(
batch_size:
200
)
do
|
project
|
RepositoryUpdateMirrorDispatchWorker
.
perform_in
(
rand
(
project
.
sync_time
/
2
),
project
.
id
)
end
end
...
...
@@ -26,6 +26,10 @@ class UpdateAllMirrorsWorker
private
def
mirrors_to_sync
Project
.
where
(
mirror:
true
,
sync_time:
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
)
...
...
config/gitlab.yml.example
View file @
7aed5e9f
...
...
@@ -212,7 +212,7 @@ production: &base
# Update mirrored repositories
update_all_mirrors_worker:
cron: "
0
* * * *"
cron: "
*/15
* * * *"
# Update remote mirrors
update_all_remote_mirrors_worker:
...
...
config/initializers/1_settings.rb
View file @
7aed5e9f
...
...
@@ -223,7 +223,6 @@ 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'
...
...
@@ -255,6 +254,7 @@ Settings.gitlab['default_projects_features'] ||= {}
Settings
.
gitlab
[
'webhook_timeout'
]
||=
10
Settings
.
gitlab
[
'max_attachment_size'
]
||=
10
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
[
'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?
...
...
@@ -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'
][
'job_class'
]
=
'HistoricalDataWorker'
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_remote_mirrors_worker'
]
||=
Settingslogic
.
new
({})
Settings
.
cron_jobs
[
'update_all_remote_mirrors_worker'
][
'cron'
]
||=
'30 * * * *'
...
...
lib/gitlab/mirror.rb
View file @
7aed5e9f
module
Gitlab
module
Mirror
QUARTER
=
15
HOUR
=
60
DAY
=
1440
FIFTEEN
=
15
HOUR
LY
=
60
DAY
LY
=
1440
class
<<
self
def
mirror
_options
def
sync_time
_options
{
"Update every 15 minutes"
:
QUARTER
,
"Update hourly"
:
HOUR
,
"Update every day"
:
DA
Y
,
"Update every 15 minutes"
=>
FIFTEEN
,
"Update hourly"
=>
HOURLY
,
"Update every day"
=>
DAYL
Y
,
}
end
def
to_cron
(
sync_time
)
case
sync_time
when
QUARTER
"*/15 * * * *"
when
HOUR
"0 * * * *"
when
DAY
"0 0 * * *"
end
def
sync_times
sync_times
=
[
FIFTEEN
]
sync_times
<<
DAYLY
if
at_beginning_of_day?
sync_times
<<
HOURLY
if
at_beginning_of_hour?
return
sync_times
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
...
...
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