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
b546ade1
Commit
b546ade1
authored
Mar 07, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Call Geo:: RepositoryBackfillService instead of worker
parent
ee99b4d3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
28 deletions
+19
-28
app/services/geo/repository_backfill_service.rb
app/services/geo/repository_backfill_service.rb
+2
-6
app/workers/geo_backfill_worker.rb
app/workers/geo_backfill_worker.rb
+6
-2
app/workers/geo_single_repository_backfill_worker.rb
app/workers/geo_single_repository_backfill_worker.rb
+0
-9
spec/services/geo/repository_backfill_service_spec.rb
spec/services/geo/repository_backfill_service_spec.rb
+3
-3
spec/workers/geo_backfill_worker_spec.rb
spec/workers/geo_backfill_worker_spec.rb
+8
-8
No files found.
app/services/geo/repository_backfill_service.rb
View file @
b546ade1
module
Geo
class
RepositoryBackfillService
attr_reader
:project_id
,
:backfill_lease
attr_reader
:project_id
LEASE_TIMEOUT
=
8
.
hours
.
freeze
LEASE_KEY_PREFIX
=
'repository_backfill_service'
.
freeze
def
initialize
(
project_id
,
backfill_lease
)
def
initialize
(
project_id
)
@project_id
=
project_id
@backfill_lease
=
backfill_lease
end
def
execute
...
...
@@ -19,9 +18,6 @@ module Geo
end
rescue
ActiveRecord
::
RecordNotFound
logger
.
error
(
"Couldn't find project with ID=
#{
project_id
}
, skipping syncing"
)
ensure
log
(
'Releasing leases to sync repositories'
)
Gitlab
::
ExclusiveLease
.
cancel
(
LEASE_KEY_PREFIX
,
backfill_lease
)
end
private
...
...
app/workers/geo_backfill_worker.rb
View file @
b546ade1
...
...
@@ -27,7 +27,7 @@ class GeoBackfillWorker
# one repo at a time. If we don't obtain the lease here, every 5
# minutes all of 100 projects will be synced.
try_obtain_lease
do
|
lease
|
Geo
SingleRepositoryBackfillWorker
.
new
.
perform
(
project_id
,
lease
)
Geo
::
RepositoryBackfillService
.
new
(
project_id
).
execute
end
rescue
ActiveRecord
::
RecordNotFound
logger
.
error
(
"Couldn't find project with ID=
#{
project_id
}
, skipping syncing"
)
...
...
@@ -65,7 +65,11 @@ class GeoBackfillWorker
return
unless
lease
yield
lease
begin
yield
lease
ensure
Gitlab
::
ExclusiveLease
.
cancel
(
lease_key
,
lease
)
end
end
def
lease_key
...
...
app/workers/geo_single_repository_backfill_worker.rb
deleted
100644 → 0
View file @
ee99b4d3
class
GeoSingleRepositoryBackfillWorker
include
Sidekiq
::
Worker
include
::
GeoDynamicBackoff
include
GeoQueue
def
perform
(
project_id
,
lease
)
Geo
::
RepositoryBackfillService
.
new
(
project_id
,
lease
).
execute
end
end
spec/services/geo/repository_backfill_service_spec.rb
View file @
b546ade1
...
...
@@ -4,7 +4,7 @@ describe Geo::RepositoryBackfillService, services: true do
let!
(
:primary
)
{
create
(
:geo_node
,
:primary
,
host:
'primary-geo-node'
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
subject
{
described_class
.
new
(
project
.
id
,
'123456'
)
}
subject
{
described_class
.
new
(
project
.
id
)
}
describe
'#execute'
do
it
'fetches project repositories'
do
...
...
@@ -29,8 +29,8 @@ describe Geo::RepositoryBackfillService, services: true do
subject
.
execute
end
it
'releases lease
s
'
do
expect
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:cancel
).
twi
ce
.
and_call_original
it
'releases lease'
do
expect
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:cancel
).
on
ce
.
and_call_original
subject
.
execute
end
...
...
spec/workers/geo_backfill_worker_spec.rb
View file @
b546ade1
...
...
@@ -12,32 +12,32 @@ describe Geo::GeoBackfillWorker, services: true do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
)
{
true
}
end
it
'performs Geo
SingleRepositoryBackfillWorker
for each project'
do
expect
(
Geo
SingleRepositoryBackfillWorker
).
to
receive
(
:new
).
twice
.
and_return
(
spy
)
it
'performs Geo
::RepositoryBackfillService
for each project'
do
expect
(
Geo
::
RepositoryBackfillService
).
to
receive
(
:new
).
twice
.
and_return
(
spy
)
subject
.
perform
end
it
'does not perform Geo
SingleRepositoryBackfillWorker
when node is disabled'
do
it
'does not perform Geo
::RepositoryBackfillService
when node is disabled'
do
allow_any_instance_of
(
GeoNode
).
to
receive
(
:enabled?
)
{
false
}
expect
(
Geo
SingleRepositoryBackfillWorker
).
not_to
receive
(
:new
)
expect
(
Geo
::
RepositoryBackfillService
).
not_to
receive
(
:new
)
subject
.
perform
end
it
'does not perform Geo
SingleRepositoryBackfillWorker
for projects that repository exists'
do
it
'does not perform Geo
::RepositoryBackfillService
for projects that repository exists'
do
create_list
(
:project
,
2
)
expect
(
Geo
SingleRepositoryBackfillWorker
).
to
receive
(
:new
).
twice
.
and_return
(
spy
)
expect
(
Geo
::
RepositoryBackfillService
).
to
receive
(
:new
).
twice
.
and_return
(
spy
)
subject
.
perform
end
it
'does not perform Geo
SingleRepositoryBackfillWorker
when can not obtain a lease'
do
it
'does not perform Geo
::RepositoryBackfillService
when can not obtain a lease'
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
)
{
false
}
expect
(
Geo
SingleRepositoryBackfillWorker
).
not_to
receive
(
:new
)
expect
(
Geo
::
RepositoryBackfillService
).
not_to
receive
(
:new
)
subject
.
perform
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