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
0241b3b2
Commit
0241b3b2
authored
Jul 05, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Doesn't sync if the project was synced after our scheduling timestamp
parent
77b2f72c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
10 deletions
+76
-10
app/models/geo/project_registry.rb
app/models/geo/project_registry.rb
+8
-0
app/workers/geo/project_sync_worker.rb
app/workers/geo/project_sync_worker.rb
+8
-10
spec/models/geo/project_registry_spec.rb
spec/models/geo/project_registry_spec.rb
+40
-0
spec/workers/geo/project_sync_worker_spec.rb
spec/workers/geo/project_sync_worker_spec.rb
+20
-0
No files found.
app/models/geo/project_registry.rb
View file @
0241b3b2
...
...
@@ -10,4 +10,12 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
where
.
not
(
last_repository_synced_at:
nil
,
last_repository_successful_sync_at:
nil
)
.
where
(
resync_repository:
false
,
resync_wiki:
false
)
end
def
repository_synced_since?
(
timestamp
)
last_repository_synced_at
&&
last_repository_synced_at
>
timestamp
end
def
wiki_synced_since?
(
timestamp
)
last_wiki_synced_at
&&
last_wiki_synced_at
>
timestamp
end
end
app/workers/geo/project_sync_worker.rb
View file @
0241b3b2
...
...
@@ -14,24 +14,22 @@ module Geo
project
=
Project
.
find
(
project_id
)
registry
=
Geo
::
ProjectRegistry
.
find_or_initialize_by
(
project_id:
project_id
)
Geo
::
RepositorySyncService
.
new
(
project
).
execute
if
sync_repository?
(
registry
)
Geo
::
WikiSyncService
.
new
(
project
).
execute
if
sync_wiki?
(
registry
)
Geo
::
RepositorySyncService
.
new
(
project
).
execute
if
sync_repository?
(
registry
,
scheduled_time
)
Geo
::
WikiSyncService
.
new
(
project
).
execute
if
sync_wiki?
(
registry
,
scheduled_time
)
rescue
ActiveRecord
::
RecordNotFound
logger
.
error
(
"Couldn't find project with ID=
#{
project_id
}
, skipping syncing"
)
end
private
def
sync_repository?
(
registry
)
registry
.
resync_repository?
||
registry
.
last_repository_successful_sync_at
.
nil?
||
registry
.
last_repository_synced_at
.
nil?
def
sync_repository?
(
registry
,
scheduled_time
)
!
registry
.
repository_synced_since?
(
scheduled_time
)
&&
(
registry
.
resync_repository?
||
registry
.
last_repository_successful_sync_at
.
nil?
)
end
def
sync_wiki?
(
registry
)
registry
.
resync_wiki?
||
registry
.
last_wiki_successful_sync_at
.
nil?
||
registry
.
last_wiki_synced_at
.
nil?
def
sync_wiki?
(
registry
,
scheduled_time
)
!
registry
.
wiki_synced_since?
(
scheduled_time
)
&&
(
registry
.
resync_wiki?
||
registry
.
last_wiki_successful_sync_at
.
nil?
)
end
end
end
spec/models/geo/project_registry_spec.rb
View file @
0241b3b2
...
...
@@ -31,4 +31,44 @@ describe Geo::ProjectRegistry, models: true do
expect
(
described_class
.
synced
).
to
match_array
([
registry
])
end
end
describe
'#repository_synced_since?'
do
it
'returns false when last_repository_synced_at is nil'
do
subject
.
last_repository_synced_at
=
nil
expect
(
subject
.
repository_synced_since?
(
Time
.
now
)).
to
be_nil
end
it
'returns false when last_repository_synced_at before timestamp'
do
subject
.
last_repository_synced_at
=
Time
.
now
-
2
.
hours
expect
(
subject
.
repository_synced_since?
(
Time
.
now
)).
to
be
false
end
it
'returns true when last_repository_synced_at after timestamp'
do
subject
.
last_repository_synced_at
=
Time
.
now
+
2
.
hours
expect
(
subject
.
repository_synced_since?
(
Time
.
now
)).
to
be
true
end
end
describe
'#wiki_synced_since?'
do
it
'returns false when last_wiki_synced_at is nil'
do
subject
.
last_wiki_synced_at
=
nil
expect
(
subject
.
wiki_synced_since?
(
Time
.
now
)).
to
be_nil
end
it
'returns false when last_wiki_synced_at before timestamp'
do
subject
.
last_wiki_synced_at
=
Time
.
now
-
2
.
hours
expect
(
subject
.
wiki_synced_since?
(
Time
.
now
)).
to
be
false
end
it
'returns true when last_wiki_synced_at after timestamp'
do
subject
.
last_wiki_synced_at
=
Time
.
now
+
2
.
hours
expect
(
subject
.
wiki_synced_since?
(
Time
.
now
)).
to
be
true
end
end
end
spec/workers/geo/project_sync_worker_spec.rb
View file @
0241b3b2
...
...
@@ -103,5 +103,25 @@ RSpec.describe Geo::ProjectSyncWorker do
expect
(
wiki_sync_service
).
to
have_received
(
:execute
)
end
end
context
'when project repository was synced after the time the job was scheduled in'
do
it
'does not perform Geo::RepositorySyncService for the given project'
do
create
(
:geo_project_registry
,
:synced
,
:repository_dirty
,
project:
project
,
last_repository_synced_at:
Time
.
now
)
subject
.
perform
(
project
.
id
,
Time
.
now
-
5
.
minutes
)
expect
(
repository_sync_service
).
not_to
have_received
(
:execute
)
end
end
context
'when wiki repository was synced after the time the job was scheduled in'
do
it
'does not perform Geo::RepositorySyncService for the given project'
do
create
(
:geo_project_registry
,
:synced
,
:wiki_dirty
,
project:
project
,
last_wiki_synced_at:
Time
.
now
)
subject
.
perform
(
project
.
id
,
Time
.
now
-
5
.
minutes
)
expect
(
wiki_sync_service
).
not_to
have_received
(
:execute
)
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