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
b8daf73d
Commit
b8daf73d
authored
May 04, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resync repositories that have been updated recently
parent
1f8f720b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
7 deletions
+54
-7
app/workers/geo_backfill_worker.rb
app/workers/geo_backfill_worker.rb
+30
-5
spec/workers/geo/geo_backfill_worker_spec.rb
spec/workers/geo/geo_backfill_worker_spec.rb
+24
-2
No files found.
app/workers/geo_backfill_worker.rb
View file @
b8daf73d
...
...
@@ -2,15 +2,18 @@ class GeoBackfillWorker
include
Sidekiq
::
Worker
include
CronjobQueue
RUN_TIME
=
5
.
minutes
.
to_i
.
freeze
BATCH_SIZE
=
100
.
freeze
RUN_TIME
=
5
.
minutes
.
to_i
BATCH_SIZE
=
100
LAST_SYNC_INTERVAL
=
24
.
hours
def
perform
return
unless
Gitlab
::
Geo
.
configured?
return
unless
Gitlab
::
Geo
.
primary_node
.
present?
start_time
=
Time
.
now
project_ids
=
find_project_ids
project_ids_not_synced
=
find_project_ids_not_synced
project_ids_updated_recently
=
find_synced_project_ids_updated_recently
project_ids
=
interleave
(
project_ids_not_synced
,
project_ids_updated_recently
)
logger
.
info
"Started Geo backfilling for
#{
project_ids
.
length
}
project(s)"
...
...
@@ -38,12 +41,34 @@ class GeoBackfillWorker
private
def
find_project_ids
def
find_project_ids
_not_synced
Project
.
where
.
not
(
id:
Geo
::
ProjectRegistry
.
synced
.
pluck
(
:project_id
))
.
limit
(
BATCH_SIZE
)
.
pluck
(
:id
)
end
def
find_synced_project_ids_updated_recently
Geo
::
ProjectRegistry
.
where
(
project_id:
find_project_ids_updated_recently
)
.
where
(
'last_repository_synced_at <= ?'
,
LAST_SYNC_INTERVAL
.
ago
)
.
order
(
last_repository_synced_at: :asc
)
.
limit
(
BATCH_SIZE
)
.
pluck
(
:project_id
)
end
def
find_project_ids_updated_recently
Project
.
where
(
id:
Geo
::
ProjectRegistry
.
synced
.
pluck
(
:project_id
))
.
where
(
'last_repository_updated_at >= ?'
,
LAST_SYNC_INTERVAL
.
ago
)
.
pluck
(
:id
)
end
def
interleave
(
first
,
second
)
if
first
.
length
>=
second
.
length
first
.
zip
(
second
)
else
second
.
zip
(
first
).
map
(
&
:reverse
)
end
.
flatten
(
1
).
compact
.
take
(
BATCH_SIZE
)
end
def
over_time?
(
start_time
)
Time
.
now
-
start_time
>=
RUN_TIME
end
...
...
spec/workers/geo/geo_backfill_worker_spec.rb
View file @
b8daf73d
...
...
@@ -3,7 +3,8 @@ require 'spec_helper'
describe
Geo
::
GeoBackfillWorker
,
services:
true
do
let!
(
:primary
)
{
create
(
:geo_node
,
:primary
,
host:
'primary-geo-node'
)
}
let!
(
:secondary
)
{
create
(
:geo_node
,
:current
)
}
let!
(
:projects
)
{
create_list
(
:empty_project
,
2
)
}
let!
(
:project_1
)
{
create
(
:empty_project
)
}
let!
(
:project_2
)
{
create
(
:empty_project
)
}
subject
{
described_class
.
new
}
...
...
@@ -20,7 +21,7 @@ describe Geo::GeoBackfillWorker, services: true do
it
'performs Geo::RepositoryBackfillService for projects where last attempt to backfill failed'
do
Geo
::
ProjectRegistry
.
create
(
project:
Project
.
first
,
project:
project_1
,
last_repository_synced_at:
DateTime
.
now
,
last_repository_successful_sync_at:
nil
)
...
...
@@ -30,6 +31,27 @@ describe Geo::GeoBackfillWorker, services: true do
subject
.
perform
end
it
'performs Geo::RepositoryBackfillService for backfilled projects updated recently'
do
Geo
::
ProjectRegistry
.
create
(
project:
project_1
,
last_repository_synced_at:
2
.
days
.
ago
,
last_repository_successful_sync_at:
2
.
days
.
ago
)
Geo
::
ProjectRegistry
.
create
(
project:
project_2
,
last_repository_synced_at:
2
.
days
.
ago
,
last_repository_successful_sync_at:
2
.
days
.
ago
)
project_1
.
update_attribute
(
:last_repository_updated_at
,
2
.
days
.
ago
)
project_2
.
update_attribute
(
:last_repository_updated_at
,
10
.
minutes
.
ago
)
expect
(
Geo
::
RepositoryBackfillService
).
to
receive
(
:new
).
once
.
and_return
(
spy
)
subject
.
perform
end
it
'does not perform Geo::RepositoryBackfillService when tracking DB is not available'
do
allow
(
Rails
.
configuration
).
to
receive
(
:respond_to?
).
with
(
:geo_database
)
{
false
}
...
...
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