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
ea293f2f
Commit
ea293f2f
authored
Feb 15, 2017
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add changelog entry to sync_time feature
parent
70b2b72b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
95 deletions
+60
-95
changelogs/unreleased-ee/mirror-scheduler-fix.yml
changelogs/unreleased-ee/mirror-scheduler-fix.yml
+4
-0
lib/gitlab/database.rb
lib/gitlab/database.rb
+2
-2
spec/workers/update_all_mirrors_worker_spec.rb
spec/workers/update_all_mirrors_worker_spec.rb
+28
-51
spec/workers/update_all_remote_mirrors_worker.rb
spec/workers/update_all_remote_mirrors_worker.rb
+26
-42
No files found.
changelogs/unreleased-ee/mirror-scheduler-fix.yml
0 → 100644
View file @
ea293f2f
---
title
:
Try to update mirrors again after 15 minutes if the previous update failed
merge_request
:
1183
author
:
lib/gitlab/database.rb
View file @
ea293f2f
...
@@ -58,7 +58,7 @@ module Gitlab
...
@@ -58,7 +58,7 @@ module Gitlab
end
end
def
true_value
def
true_value
if
postgresql?
if
Gitlab
::
Database
.
postgresql?
"'t'"
"'t'"
else
else
1
1
...
@@ -66,7 +66,7 @@ module Gitlab
...
@@ -66,7 +66,7 @@ module Gitlab
end
end
def
false_value
def
false_value
if
postgresql?
if
Gitlab
::
Database
.
postgresql?
"'f'"
"'f'"
else
else
0
0
...
...
spec/workers/update_all_mirrors_worker_spec.rb
View file @
ea293f2f
require
'rails_helper'
require
'rails_helper'
describe
UpdateAllMirrorsWorker
do
describe
UpdateAllMirrorsWorker
do
before
do
before
{
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
).
and_return
(
true
)
}
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
)
.
to
receive
(
:try_obtain
).
and_return
(
true
)
end
describe
'#perform'
do
describe
'#perform'
do
let
(
:worker
)
{
described_class
.
new
}
let!
(
:mirror1
)
{
create
(
:empty_project
,
:mirror
,
sync_time:
Gitlab
::
Mirror
::
FIFTEEN
)
}
let!
(
:mirror1
)
{
create
(
:empty_project
,
:mirror
,
sync_time:
Gitlab
::
Mirror
::
FIFTEEN
)
}
let!
(
:mirror2
)
{
create
(
:empty_project
,
:mirror
,
sync_time:
Gitlab
::
Mirror
::
HOURLY
)
}
let!
(
:mirror2
)
{
create
(
:empty_project
,
:mirror
,
sync_time:
Gitlab
::
Mirror
::
HOURLY
)
}
let!
(
:mirror3
)
{
create
(
:empty_project
,
:mirror
,
sync_time:
Gitlab
::
Mirror
::
DAILY
)
}
let!
(
:mirror3
)
{
create
(
:empty_project
,
:mirror
,
sync_time:
Gitlab
::
Mirror
::
DAILY
)
}
let!
(
:mirror4
)
{
create
(
:empty_project
,
:mirror
)
}
let!
(
:mirror4
)
{
create
(
:empty_project
,
:mirror
)
}
it
'fails stuck mirrors'
do
it
'fails stuck mirrors'
do
worker
=
described_class
.
new
expect
(
worker
).
to
receive
(
:fail_stuck_mirrors!
)
expect
(
worker
).
to
receive
(
:fail_stuck_mirrors!
)
worker
.
perform
worker
.
perform
end
end
describe
'update times'
do
describe
'sync_time'
do
after
do
def
expect_worker_to_update_mirrors
(
mirrors
)
Timecop
.
return
mirrors
.
each
do
|
mirror
|
expect
(
worker
).
to
receive
(
:rand
).
with
((
mirror
.
sync_time
/
2
).
minutes
).
and_return
(
mirror
.
sync_time
/
2
)
expect
(
RepositoryUpdateMirrorDispatchWorker
).
to
receive
(
:perform_in
).
with
(
mirror
.
sync_time
/
2
,
mirror
.
id
)
end
end
end
describe
'fifteen'
do
def
setup
(
time
)
before
do
Timecop
.
freeze
(
time
)
time
=
DateTime
.
now
.
beginning_of_hour
+
15
.
minutes
mirror4
.
update_attributes
(
mirror_last_successful_update_at:
time
-
(
Gitlab
::
Mirror
::
DAILY
+
5
).
minutes
)
end
Timecop
.
freeze
(
time
)
describe
'fifteen'
do
mirror4
.
update_attributes
(
mirror_last_successful_update_at:
time
-
(
Gitlab
::
Mirror
::
DAILY
+
5
).
minutes
)
let
(
:mirrors
)
{
[
mirror1
,
mirror4
]
}
end
it
'enqueues a job on mirrored Projects'
do
before
{
setup
(
DateTime
.
now
.
beginning_of_hour
+
15
.
minutes
)
}
mirrors
=
[
mirror1
,
mirror4
]
worker
=
described_class
.
new
mirrors
.
each
do
|
mirror
|
it
'enqueues a job on mirrored projects'
do
expect
(
worker
).
to
receive
(
:rand
).
with
((
mirror
.
sync_time
/
2
).
minutes
).
and_return
(
mirror
.
sync_time
/
2
)
expect_worker_to_update_mirrors
(
mirrors
)
expect
(
RepositoryUpdateMirrorDispatchWorker
).
to
receive
(
:perform_in
).
with
(
mirror
.
sync_time
/
2
,
mirror
.
id
)
end
worker
.
perform
worker
.
perform
end
end
end
end
describe
'hourly'
do
describe
'hourly'
do
before
do
let
(
:mirrors
)
{
[
mirror1
,
mirror2
,
mirror4
]
}
time
=
DateTime
.
now
.
beginning_of_hour
Timecop
.
freeze
(
time
)
mirror4
.
update_attributes
(
mirror_last_successful_update_at:
time
-
(
Gitlab
::
Mirror
::
DAILY
+
5
).
minutes
)
end
it
'enqueues a job on mirrored Projects'
do
before
{
setup
(
DateTime
.
now
.
beginning_of_hour
)
}
mirrors
=
[
mirror1
,
mirror2
,
mirror4
]
worker
=
described_class
.
new
mirrors
.
each
do
|
mirror
|
it
'enqueues a job on mirrored projects'
do
expect
(
worker
).
to
receive
(
:rand
).
with
((
mirror
.
sync_time
/
2
).
minutes
).
and_return
(
mirror
.
sync_time
/
2
)
expect_worker_to_update_mirrors
(
mirrors
)
expect
(
RepositoryUpdateMirrorDispatchWorker
).
to
receive
(
:perform_in
).
with
(
mirror
.
sync_time
/
2
,
mirror
.
id
)
end
worker
.
perform
worker
.
perform
end
end
end
end
describe
'daily'
do
describe
'daily'
do
before
do
let
(
:mirrors
)
{
[
mirror1
,
mirror2
,
mirror3
,
mirror4
]
}
time
=
DateTime
.
now
.
beginning_of_day
Timecop
.
freeze
(
time
)
before
{
setup
(
DateTime
.
now
.
beginning_of_day
)
}
mirror4
.
update_attributes
(
mirror_last_successful_update_at:
time
-
(
Gitlab
::
Mirror
::
DAILY
+
5
).
minutes
)
end
it
'enqueues a job on mirrored Projects'
do
mirrors
=
[
mirror1
,
mirror2
,
mirror3
,
mirror4
]
worker
=
described_class
.
new
mirrors
.
each
do
|
mirror
|
it
'enqueues a job on mirrored projects'
do
expect
(
worker
).
to
receive
(
:rand
).
with
((
mirror
.
sync_time
/
2
).
minutes
).
and_return
(
mirror
.
sync_time
/
2
)
expect_worker_to_update_mirrors
(
mirrors
)
expect
(
RepositoryUpdateMirrorDispatchWorker
).
to
receive
(
:perform_in
).
with
(
mirror
.
sync_time
/
2
,
mirror
.
id
)
end
worker
.
perform
worker
.
perform
end
end
end
end
after
{
Timecop
.
return
}
end
end
it
'does not execute if cannot get the lease'
do
it
'does not execute if cannot get the lease'
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
)
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
).
and_return
(
false
)
.
to
receive
(
:try_obtain
).
and_return
(
false
)
worker
=
described_class
.
new
create
(
:empty_project
,
:mirror
)
create
(
:empty_project
,
:mirror
)
expect
(
worker
).
not_to
receive
(
:fail_stuck_mirrors!
)
expect
(
worker
).
not_to
receive
(
:fail_stuck_mirrors!
)
...
...
spec/workers/update_all_remote_mirrors_worker.rb
View file @
ea293f2f
require
'rails_helper'
require
'rails_helper'
describe
UpdateAllRemoteMirrorsWorker
do
describe
UpdateAllRemoteMirrorsWorker
do
describe
"#perform"
do
let
(
:worker
)
{
described_class
.
new
}
describe
"#perform"
do
let!
(
:mirror1
)
{
create
(
:project
,
:remote_mirror
,
sync_time:
Gitlab
::
Mirror
::
FIFTEEN
)
}
let!
(
:mirror1
)
{
create
(
:project
,
:remote_mirror
,
sync_time:
Gitlab
::
Mirror
::
FIFTEEN
)
}
let!
(
:mirror2
)
{
create
(
:project
,
:remote_mirror
,
sync_time:
Gitlab
::
Mirror
::
HOURLY
)
}
let!
(
:mirror2
)
{
create
(
:project
,
:remote_mirror
,
sync_time:
Gitlab
::
Mirror
::
HOURLY
)
}
let!
(
:mirror3
)
{
create
(
:project
,
:remote_mirror
,
sync_time:
Gitlab
::
Mirror
::
DAILY
)
}
let!
(
:mirror3
)
{
create
(
:project
,
:remote_mirror
,
sync_time:
Gitlab
::
Mirror
::
DAILY
)
}
let!
(
:mirror4
)
{
create
(
:project
,
:remote_mirror
,
sync_time:
Gitlab
::
Mirror
::
DAILY
)
}
let!
(
:mirror4
)
{
create
(
:project
,
:remote_mirror
,
sync_time:
Gitlab
::
Mirror
::
DAILY
)
}
it
'fails stuck mirrors'
do
it
'fails stuck mirrors'
do
worker
=
described_class
.
new
expect
(
worker
).
to
receive
(
:fail_stuck_mirrors!
)
expect
(
worker
).
to
receive
(
:fail_stuck_mirrors!
)
worker
.
perform
worker
.
perform
end
end
describe
'update times'
do
describe
'sync time'
do
after
do
def
expect_worker_to_update_mirrors
(
mirrors
)
Timecop
.
return
mirrors
.
each
do
|
mirror
|
expect
(
RepositoryUpdateRemoteMirrorWorker
).
to
receive
(
:perform_async
).
with
(
mirror
.
id
)
end
end
end
describe
'fifteen'
do
def
setup
(
time
)
before
do
Timecop
.
freeze
(
time
)
time
=
DateTime
.
now
.
beginning_of_hour
+
15
.
minutes
mirror4
.
remote_mirrors
.
first
.
update_attributes
(
last_successful_update_at:
time
-
(
Gitlab
::
Mirror
::
DAILY
+
5
).
minutes
)
end
Timecop
.
freeze
(
time
)
describe
'fifteen'
do
mirror4
.
remote_mirrors
.
first
.
update_attributes
(
last_successful_update_at:
time
-
(
Gitlab
::
Mirror
::
DAILY
+
5
).
minutes
)
let
(
:mirrors
)
{
[
mirror1
,
mirror4
]
}
end
it
'enqueues a job on mirrored Projects'
do
before
{
setup
(
DateTime
.
now
.
beginning_of_hour
+
15
.
minutes
)
}
mirrors
=
[
mirror1
,
mirror4
]
worker
=
described_class
.
new
mirrors
.
each
do
|
mirror
|
it
'enqueues a job on remote mirrored projects'
do
expect
(
RepositoryUpdateRemoteMirrorWorker
).
to
receive
(
:perform_async
).
with
(
mirror
.
id
)
expect_worker_to_update_mirrors
(
mirrors
)
end
worker
.
perform
worker
.
perform
end
end
end
end
describe
"hourly"
do
describe
"hourly"
do
before
do
let
(
:mirrors
)
{
[
mirror1
,
mirror2
,
mirror4
]
}
time
=
DateTime
.
now
.
beginning_of_hour
Timecop
.
freeze
(
time
)
mirror4
.
remote_mirrors
.
first
.
update_attributes
(
last_successful_update_at:
time
-
(
Gitlab
::
Mirror
::
DAILY
+
5
).
minutes
)
end
it
'enqueues a job on mirrored Projects'
do
before
{
setup
(
DateTime
.
now
.
beginning_of_hour
)
}
mirrors
=
[
mirror1
,
mirror2
,
mirror4
]
worker
=
described_class
.
new
mirrors
.
each
do
|
mirror
|
it
'enqueues a job on remote mirrored projects'
do
expect
(
RepositoryUpdateRemoteMirrorWorker
).
to
receive
(
:perform_async
).
with
(
mirror
.
id
)
expect_worker_to_update_mirrors
(
mirrors
)
end
worker
.
perform
worker
.
perform
end
end
end
end
describe
"daily"
do
describe
"daily"
do
before
do
let
(
:mirrors
)
{
[
mirror1
,
mirror2
,
mirror3
,
mirror4
]
}
time
=
DateTime
.
now
.
beginning_of_day
Timecop
.
freeze
(
time
)
before
{
setup
(
DateTime
.
now
.
beginning_of_day
)
}
mirror4
.
remote_mirrors
.
first
.
update_attributes
(
last_successful_update_at:
time
-
(
Gitlab
::
Mirror
::
DAILY
+
5
).
minutes
)
end
it
'enqueues a job on mirrored Projects'
do
mirrors
=
[
mirror1
,
mirror2
,
mirror3
,
mirror4
]
worker
=
described_class
.
new
mirrors
.
each
do
|
mirror
|
it
'enqueues a job on remote mirrored projects'
do
expect
(
RepositoryUpdateRemoteMirrorWorker
).
to
receive
(
:perform_async
).
with
(
mirror
.
id
)
expect_worker_to_update_mirrors
(
mirrors
)
end
worker
.
perform
worker
.
perform
end
end
end
end
after
{
Timecop
.
return
}
end
end
end
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