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
380a7636
Commit
380a7636
authored
Jul 05, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Schedule a job to sync the project with a backoff delay of 5 minutes
parent
d3a1a5ce
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
36 deletions
+23
-36
app/workers/geo_repository_sync_worker.rb
app/workers/geo_repository_sync_worker.rb
+4
-36
spec/workers/geo/project_sync_worker_spec.rb
spec/workers/geo/project_sync_worker_spec.rb
+19
-0
No files found.
app/workers/geo_repository_sync_worker.rb
View file @
380a7636
...
...
@@ -4,6 +4,7 @@ class GeoRepositorySyncWorker
RUN_TIME
=
5
.
minutes
.
to_i
BATCH_SIZE
=
100
BACKOFF_DELAY
=
5
.
minutes
def
perform
return
unless
Gitlab
::
Geo
.
secondary_role_enabled?
...
...
@@ -17,23 +18,10 @@ class GeoRepositorySyncWorker
logger
.
info
"Started Geo repository syncing for
#{
project_ids
.
length
}
project(s)"
project_ids
.
each
do
|
project_id
|
begin
break
if
over_time?
(
start_time
)
break
unless
node_enabled?
break
if
over_time?
(
start_time
)
break
unless
node_enabled?
# We try to obtain a lease here for the entire sync process because we
# want to sync the repositories continuously at a controlled rate
# instead of hammering the primary node. Initially, we are syncing
# 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
::
RepositorySyncService
.
new
(
project_id
).
execute
end
rescue
ActiveRecord
::
RecordNotFound
logger
.
error
(
"Couldn't find project with ID=
#{
project_id
}
, skipping syncing"
)
next
end
Geo
::
ProjectSyncWorker
.
perform_in
(
BACKOFF_DELAY
,
project_id
,
Time
.
now
)
end
logger
.
info
"Finished Geo repository syncing for
#{
project_ids
.
length
}
project(s)"
...
...
@@ -76,24 +64,4 @@ class GeoRepositorySyncWorker
@current_node_enabled
||=
Gitlab
::
Geo
.
current_node_enabled?
end
def
try_obtain_lease
lease
=
Gitlab
::
ExclusiveLease
.
new
(
lease_key
,
timeout:
lease_timeout
).
try_obtain
return
unless
lease
begin
yield
lease
ensure
Gitlab
::
ExclusiveLease
.
cancel
(
lease_key
,
lease
)
end
end
def
lease_key
Geo
::
RepositorySyncService
::
LEASE_KEY_PREFIX
end
def
lease_timeout
Geo
::
RepositorySyncService
::
LEASE_TIMEOUT
end
end
spec/workers/geo/project_sync_worker_spec.rb
0 → 100644
View file @
380a7636
require
'rails_helper'
RSpec
.
describe
Geo
::
ProjectSyncWorker
do
subject
{
described_class
.
new
}
describe
'#perform'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:repository_sync_service
)
{
spy
}
it
'performs Geo::RepositorySyncService for the given project'
do
allow
(
Geo
::
RepositorySyncService
).
to
receive
(
:new
)
.
with
(
project
.
id
).
once
.
and_return
(
repository_sync_service
)
subject
.
perform
(
project
.
id
,
Time
.
now
)
expect
(
repository_sync_service
).
to
have_received
(
:execute
).
once
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