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
73fa41ec
Commit
73fa41ec
authored
Jun 28, 2017
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds logging when mirror starts and finishes
parent
27a22281
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
3 deletions
+51
-3
app/models/ee/project.rb
app/models/ee/project.rb
+15
-0
app/workers/repository_update_mirror_worker.rb
app/workers/repository_update_mirror_worker.rb
+6
-2
spec/factories/projects.rb
spec/factories/projects.rb
+8
-0
spec/models/ee/project_spec.rb
spec/models/ee/project_spec.rb
+21
-0
spec/workers/repository_update_mirror_worker_spec.rb
spec/workers/repository_update_mirror_worker_spec.rb
+1
-1
No files found.
app/models/ee/project.rb
View file @
73fa41ec
...
@@ -84,6 +84,20 @@ module EE
...
@@ -84,6 +84,20 @@ module EE
mirror?
&&
self
.
mirror_last_update_at
mirror?
&&
self
.
mirror_last_update_at
end
end
def
mirror_waiting_duration
return
unless
mirror?
(
mirror_data
.
last_update_started_at
.
to_i
-
mirror_data
.
last_update_scheduled_at
.
to_i
).
seconds
end
def
mirror_update_duration
return
unless
mirror?
(
mirror_last_update_at
.
to_i
-
mirror_data
.
last_update_started_at
.
to_i
).
seconds
end
def
mirror_with_content?
def
mirror_with_content?
mirror?
&&
!
empty_repo?
mirror?
&&
!
empty_repo?
end
end
...
@@ -190,6 +204,7 @@ module EE
...
@@ -190,6 +204,7 @@ module EE
super
super
elsif
mirror?
elsif
mirror?
::
Gitlab
::
Mirror
.
increment_metric
(
:mirrors_scheduled
,
'Mirrors scheduled count'
)
::
Gitlab
::
Mirror
.
increment_metric
(
:mirrors_scheduled
,
'Mirrors scheduled count'
)
Rails
.
logger
.
info
(
"Mirror update for
#{
full_path
}
was scheduled."
)
RepositoryUpdateMirrorWorker
.
perform_async
(
self
.
id
)
RepositoryUpdateMirrorWorker
.
perform_async
(
self
.
id
)
end
end
...
...
app/workers/repository_update_mirror_worker.rb
View file @
73fa41ec
...
@@ -41,19 +41,23 @@ class RepositoryUpdateMirrorWorker
...
@@ -41,19 +41,23 @@ class RepositoryUpdateMirrorWorker
def
start_mirror
(
project
)
def
start_mirror
(
project
)
project
.
import_start
project
.
import_start
Gitlab
::
Mirror
.
increment_metric
(
:mirrors_running
,
'Mirrors running count'
)
Gitlab
::
Mirror
.
increment_metric
(
:mirrors_running
,
'Mirrors running count'
)
Rails
.
logger
.
info
(
"Mirror update for
#{
project
.
full_path
}
started. Waiting duration:
#{
project
.
mirror_waiting_duration
}
"
)
end
end
def
fail_mirror
(
project
,
message
)
def
fail_mirror
(
project
,
message
)
project
.
mark_import_as_failed
(
message
)
error_message
=
"Mirror update for
#{
project
.
full_path
}
failed with the following message:
#{
message
}
"
project
.
mark_import_as_failed
(
error_message
)
Gitlab
::
Mirror
.
increment_metric
(
:mirrors_failed
,
'Mirrors failed count'
)
Gitlab
::
Mirror
.
increment_metric
(
:mirrors_failed
,
'Mirrors failed count'
)
Rails
.
logger
.
error
(
message
)
Rails
.
logger
.
error
(
error_
message
)
end
end
def
finish_mirror
(
project
)
def
finish_mirror
(
project
)
project
.
import_finish
project
.
import_finish
Gitlab
::
Mirror
.
increment_metric
(
:mirrors_finished
,
'Mirrors successfully finished count'
)
Gitlab
::
Mirror
.
increment_metric
(
:mirrors_finished
,
'Mirrors successfully finished count'
)
Rails
.
logger
.
info
(
"Mirror update for
#{
project
.
full_path
}
successfully finished. Update duration:
#{
project
.
mirror_update_duration
}
}."
)
end
end
end
end
spec/factories/projects.rb
View file @
73fa41ec
...
@@ -28,10 +28,18 @@ FactoryGirl.define do
...
@@ -28,10 +28,18 @@ FactoryGirl.define do
trait
:import_scheduled
do
trait
:import_scheduled
do
import_status
:scheduled
import_status
:scheduled
after
(
:create
)
do
|
project
,
_
|
project
.
mirror_data
&
.
update_attributes
(
last_update_scheduled_at:
Time
.
now
)
end
end
end
trait
:import_started
do
trait
:import_started
do
import_status
:started
import_status
:started
after
(
:create
)
do
|
project
,
_
|
project
.
mirror_data
&
.
update_attributes
(
last_update_started_at:
Time
.
now
)
end
end
end
trait
:import_finished
do
trait
:import_finished
do
...
...
spec/models/ee/project_spec.rb
View file @
73fa41ec
...
@@ -117,6 +117,27 @@ describe Project, models: true do
...
@@ -117,6 +117,27 @@ describe Project, models: true do
end
end
end
end
describe
'#mirror_waiting_duration'
do
it
'returns in seconds the time spent in the queue'
do
project
=
create
(
:empty_project
,
:mirror
,
:import_scheduled
)
mirror_data
=
project
.
mirror_data
mirror_data
.
update_attributes
(
last_update_started_at:
mirror_data
.
last_update_scheduled_at
+
5
.
minutes
)
expect
(
project
.
mirror_waiting_duration
).
to
eq
(
300
)
end
end
describe
'#mirror_update_duration'
do
it
'returns in seconds the time spent updating'
do
project
=
create
(
:empty_project
,
:mirror
,
:import_started
)
project
.
update_attributes
(
mirror_last_update_at:
project
.
mirror_data
.
last_update_started_at
+
5
.
minutes
)
expect
(
project
.
mirror_update_duration
).
to
eq
(
300
)
end
end
describe
'#any_runners_limit'
do
describe
'#any_runners_limit'
do
let
(
:project
)
{
create
(
:empty_project
,
shared_runners_enabled:
shared_runners_enabled
)
}
let
(
:project
)
{
create
(
:empty_project
,
shared_runners_enabled:
shared_runners_enabled
)
}
let
(
:specific_runner
)
{
create
(
:ci_runner
)
}
let
(
:specific_runner
)
{
create
(
:ci_runner
)
}
...
...
spec/workers/repository_update_mirror_worker_spec.rb
View file @
73fa41ec
...
@@ -49,7 +49,7 @@ describe RepositoryUpdateMirrorWorker do
...
@@ -49,7 +49,7 @@ describe RepositoryUpdateMirrorWorker do
end
end
context
'threshold_reached?'
do
context
'threshold_reached?'
do
let
(
:mirror
)
{
create
(
:project
,
:mirror
)
}
let
(
:mirror
)
{
create
(
:project
,
:mirror
,
:import_scheduled
)
}
before
do
before
do
expect_any_instance_of
(
Projects
::
UpdateMirrorService
).
to
receive
(
:execute
).
and_return
(
status: :success
)
expect_any_instance_of
(
Projects
::
UpdateMirrorService
).
to
receive
(
:execute
).
and_return
(
status: :success
)
...
...
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