Commit 27a22281 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'improve-mirroring-documentation-and-force-update-button-transparency' into 'master'

Improves mirror force update button transparency

See merge request !2299
parents 87a822e6 e0635c39
...@@ -84,11 +84,19 @@ module EE ...@@ -84,11 +84,19 @@ module EE
mirror? && self.mirror_last_update_at mirror? && self.mirror_last_update_at
end end
def updating_mirror? def mirror_with_content?
return false unless mirror? && !empty_repo? mirror? && !empty_repo?
return true if import_in_progress? end
def scheduled_mirror?
return false unless mirror_with_content?
return true if import_scheduled?
self.mirror_data.next_execution_timestamp < Time.now self.mirror_data.next_execution_timestamp <= Time.now
end
def updating_mirror?
mirror_with_content? && import_started?
end end
def mirror_last_update_status def mirror_last_update_status
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
= expanded ? 'Collapse' : 'Expand' = expanded ? 'Collapse' : 'Expand'
%p %p
Set up your project to automatically have its branches, tags, and commits Set up your project to automatically have its branches, tags, and commits
updated from an upstream repository every hour. updated from an upstream repository.
= link_to 'Read more', help_page_path('workflow/repository_mirroring', anchor: 'pulling-from-a-remote-repository'), target: '_blank' = link_to 'Read more', help_page_path('workflow/repository_mirroring', anchor: 'pulling-from-a-remote-repository'), target: '_blank'
.settings-content.no-animate{ class: ('expanded' if expanded) } .settings-content.no-animate{ class: ('expanded' if expanded) }
= form_for @project, url: namespace_project_mirror_path(@project.namespace, @project) do |f| = form_for @project, url: namespace_project_mirror_path(@project.namespace, @project) do |f|
...@@ -30,8 +30,6 @@ ...@@ -30,8 +30,6 @@
= f.check_box :mirror, class: "pull-left" = f.check_box :mirror, class: "pull-left"
.prepend-left-20 .prepend-left-20
= f.label :mirror, "Mirror repository", class: "label-light append-bottom-0" = f.label :mirror, "Mirror repository", class: "label-light append-bottom-0"
%p.light.append-bottom-0
Automatically update this project's branches, tags, and commits from the upstream repository every hour.
.form-group .form-group
= f.label :import_url, "Git repository URL", class: "label-light" = f.label :import_url, "Git repository URL", class: "label-light"
= f.text_field :import_url, class: 'form-control', placeholder: 'https://username:password@gitlab.company.com/group/project.git' = f.text_field :import_url, class: 'form-control', placeholder: 'https://username:password@gitlab.company.com/group/project.git'
......
- if @project.mirror? && can?(current_user, :push_code, @project) - if @project.mirror? && can?(current_user, :push_code, @project)
.append-bottom-default .append-bottom-default
- if @project.updating_mirror? - if @project.scheduled_mirror?
%span.btn.disabled
= icon("refresh spin")
Update Scheduled&hellip;
- elsif @project.updating_mirror?
%span.btn.disabled %span.btn.disabled
= icon("refresh spin") = icon("refresh spin")
Updating&hellip; Updating&hellip;
......
...@@ -6,8 +6,8 @@ Repository Mirroring is a way to mirror repositories from external sources. ...@@ -6,8 +6,8 @@ Repository Mirroring is a way to mirror repositories from external sources.
It can be used to mirror all branches, tags, and commits that you have It can be used to mirror all branches, tags, and commits that you have
in your repository. in your repository.
Your mirror at GitLab will be updated automatically once an hour, but you can Your mirror at GitLab will be updated automatically. You can
also manually update it whenever you need. also manually trigger an update at most once every 5 minutes.
## Overview ## Overview
...@@ -19,10 +19,11 @@ There are two kinds of repository mirroring features supported by GitLab: ...@@ -19,10 +19,11 @@ There are two kinds of repository mirroring features supported by GitLab:
to another location, whereas the **pull** method mirrors an external repository to another location, whereas the **pull** method mirrors an external repository
in one in GitLab. in one in GitLab.
By default, mirror repositories are updated every hour, and all new branches, Once the mirror repository is updated, all new branches,
tags, and commits will be visible in the project's activity feed. tags, and commits will be visible in the project's activity feed.
Users with at least [developer access][perms] to the project can also force an Users with at least [developer access][perms] to the project can also force an
immediate update with a click of a button. immediate update with the click of a button. This button will not be available if
the mirror is already being updated or 5 minutes still haven't passed since its last update.
A few things/limitations to consider: A few things/limitations to consider:
...@@ -82,6 +83,18 @@ this branch to prevent any changes from being lost. ...@@ -82,6 +83,18 @@ this branch to prevent any changes from being lost.
![Diverged branch](repository_mirroring/repository_mirroring_diverged_branch.png) ![Diverged branch](repository_mirroring/repository_mirroring_diverged_branch.png)
## How it works
Once you activate the pull mirroring feature, the mirror will be inserted into a queue.
A scheduler will start every minute and schedule a fixed amount of mirrors for update, based
on the configured maximum capacity.
If the mirror successfully updates it will be enqueued once again with a small backoff
period.
If the mirror fails (eg: branch diverged from upstream), the project's
backoff period will be penalized each time it fails up to a maximum amount of time.
## Pushing to a remote repository ## Pushing to a remote repository
For an existing project, you can set up mirror pushing by visiting your project's For an existing project, you can set up mirror pushing by visiting your project's
......
...@@ -1864,6 +1864,28 @@ describe Project, models: true do ...@@ -1864,6 +1864,28 @@ describe Project, models: true do
end end
end end
describe '#scheduled_mirror?' do
context 'when mirror is expected to run soon' do
it 'returns true' do
timestamp = Time.now
project = create(:project, :mirror, :import_finished)
project.mirror_last_update_at = timestamp - 3.minutes
project.mirror_data.next_execution_timestamp = timestamp - 2.minutes
expect(project.scheduled_mirror?).to be true
end
end
context 'when mirror was scheduled' do
it 'returns true' do
project = create(:project, :mirror, :import_scheduled)
expect(project.scheduled_mirror?).to be true
end
end
end
describe '#updating_mirror?' do describe '#updating_mirror?' do
context 'when repository is empty' do context 'when repository is empty' do
it 'returns false' do it 'returns false' do
...@@ -1881,25 +1903,13 @@ describe Project, models: true do ...@@ -1881,25 +1903,13 @@ describe Project, models: true do
end end
end end
context 'when project is in progress' do context 'when mirror is in progress' do
it 'returns true' do it 'returns true' do
project = create(:project, :mirror, :import_started) project = create(:project, :mirror, :import_started)
expect(project.updating_mirror?).to be true expect(project.updating_mirror?).to be true
end end
end end
context 'when project is expected to run soon' do
it 'returns true' do
timestamp = Time.now
project = create(:project, :mirror, :import_finished)
project.mirror_last_update_at = timestamp - 3.minutes
project.mirror_data.next_execution_timestamp = timestamp - 2.minutes
expect(project.updating_mirror?).to be true
end
end
end end
describe '#force_import_job!' do describe '#force_import_job!' do
......
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