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
d3a1a5ce
Commit
d3a1a5ce
authored
Jul 05, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Geo::ProjectSyncWorker
parent
3283c713
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
20 deletions
+31
-20
app/workers/geo/project_sync_worker.rb
app/workers/geo/project_sync_worker.rb
+19
-0
spec/workers/geo_repository_sync_worker_spec.rb
spec/workers/geo_repository_sync_worker_spec.rb
+12
-20
No files found.
app/workers/geo/project_sync_worker.rb
0 → 100644
View file @
d3a1a5ce
module
Geo
class
ProjectSyncWorker
include
Sidekiq
::
Worker
sidekiq_options
queue: :geo
,
retry:
3
,
dead:
false
sidekiq_retry_in
{
|
count
|
30
*
count
}
sidekiq_retries_exhausted
do
|
msg
,
_
|
Sidekiq
.
logger
.
warn
"Failed
#{
msg
[
'class'
]
}
with
#{
msg
[
'args'
]
}
:
#{
msg
[
'error_message'
]
}
"
end
def
perform
(
project_id
,
scheduled_time
)
Geo
::
RepositorySyncService
.
new
(
project_id
).
execute
rescue
ActiveRecord
::
RecordNotFound
logger
.
error
(
"Couldn't find project with ID=
#{
project_id
}
, skipping syncing"
)
end
end
end
spec/workers/geo_repository_sync_worker_spec.rb
View file @
d3a1a5ce
...
@@ -13,13 +13,13 @@ describe GeoRepositorySyncWorker do
...
@@ -13,13 +13,13 @@ describe GeoRepositorySyncWorker do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
)
{
true
}
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
)
{
true
}
end
end
it
'performs Geo::
RepositorySyncService
for each project'
do
it
'performs Geo::
ProjectSyncWorker
for each project'
do
expect
(
Geo
::
RepositorySyncService
).
to
receive
(
:new
).
twice
.
and_return
(
spy
)
expect
(
Geo
::
ProjectSyncWorker
).
to
receive
(
:perform_in
).
twice
.
and_return
(
spy
)
subject
.
perform
subject
.
perform
end
end
it
'performs Geo::
RepositorySyncService
for projects where last attempt to sync failed'
do
it
'performs Geo::
ProjectSyncWorker
for projects where last attempt to sync failed'
do
Geo
::
ProjectRegistry
.
create
(
Geo
::
ProjectRegistry
.
create
(
project:
project_1
,
project:
project_1
,
last_repository_synced_at:
DateTime
.
now
,
last_repository_synced_at:
DateTime
.
now
,
...
@@ -34,12 +34,12 @@ describe GeoRepositorySyncWorker do
...
@@ -34,12 +34,12 @@ describe GeoRepositorySyncWorker do
resync_wiki:
false
resync_wiki:
false
)
)
expect
(
Geo
::
RepositorySyncService
).
to
receive
(
:new
).
once
.
and_return
(
spy
)
expect
(
Geo
::
ProjectSyncWorker
).
to
receive
(
:perform_in
).
once
.
and_return
(
spy
)
subject
.
perform
subject
.
perform
end
end
it
'performs Geo::
RepositorySyncService
for synced projects updated recently'
do
it
'performs Geo::
ProjectSyncWorker
for synced projects updated recently'
do
Geo
::
ProjectRegistry
.
create
(
Geo
::
ProjectRegistry
.
create
(
project:
project_1
,
project:
project_1
,
last_repository_synced_at:
2
.
days
.
ago
,
last_repository_synced_at:
2
.
days
.
ago
,
...
@@ -64,39 +64,31 @@ describe GeoRepositorySyncWorker do
...
@@ -64,39 +64,31 @@ describe GeoRepositorySyncWorker do
resync_wiki:
true
resync_wiki:
true
)
)
expect
(
Geo
::
RepositorySyncService
).
to
receive
(
:new
).
twice
.
and_return
(
spy
)
expect
(
Geo
::
ProjectSyncWorker
).
to
receive
(
:perform_in
).
twice
.
and_return
(
spy
)
subject
.
perform
subject
.
perform
end
end
it
'does not perform Geo::
RepositorySyncService
when secondary role is disabled'
do
it
'does not perform Geo::
ProjectSyncWorker
when secondary role is disabled'
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:secondary_role_enabled?
)
{
false
}
allow
(
Gitlab
::
Geo
).
to
receive
(
:secondary_role_enabled?
)
{
false
}
expect
(
Geo
::
RepositorySyncService
).
not_to
receive
(
:new
)
expect
(
Geo
::
ProjectSyncWorker
).
not_to
receive
(
:perform_in
)
subject
.
perform
subject
.
perform
end
end
it
'does not perform Geo::
RepositorySyncService
when primary node does not exists'
do
it
'does not perform Geo::
ProjectSyncWorker
when primary node does not exists'
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:primary_node
)
{
nil
}
allow
(
Gitlab
::
Geo
).
to
receive
(
:primary_node
)
{
nil
}
expect
(
Geo
::
RepositorySyncService
).
not_to
receive
(
:new
)
expect
(
Geo
::
ProjectSyncWorker
).
not_to
receive
(
:perform_in
)
subject
.
perform
subject
.
perform
end
end
it
'does not perform Geo::
RepositorySyncService
when node is disabled'
do
it
'does not perform Geo::
ProjectSyncWorker
when node is disabled'
do
allow_any_instance_of
(
GeoNode
).
to
receive
(
:enabled?
)
{
false
}
allow_any_instance_of
(
GeoNode
).
to
receive
(
:enabled?
)
{
false
}
expect
(
Geo
::
RepositorySyncService
).
not_to
receive
(
:new
)
expect
(
Geo
::
ProjectSyncWorker
).
not_to
receive
(
:perform_in
)
subject
.
perform
end
it
'does not perform Geo::RepositorySyncService when can not obtain a lease'
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
)
{
false
}
expect
(
Geo
::
RepositorySyncService
).
not_to
receive
(
:new
)
subject
.
perform
subject
.
perform
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