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
eaf4cfd1
Commit
eaf4cfd1
authored
Nov 11, 2019
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an event handler for design repository update events
parent
b23e59e6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
151 additions
and
1 deletion
+151
-1
ee/lib/gitlab/geo/log_cursor/events/design_repository_updated_event.rb
.../geo/log_cursor/events/design_repository_updated_event.rb
+49
-0
ee/spec/factories/geo/event_log.rb
ee/spec/factories/geo/event_log.rb
+13
-1
ee/spec/lib/gitlab/geo/log_cursor/events/design_repository_updated_event_spec.rb
...log_cursor/events/design_repository_updated_event_spec.rb
+89
-0
No files found.
ee/lib/gitlab/geo/log_cursor/events/design_repository_updated_event.rb
0 → 100644
View file @
eaf4cfd1
# frozen_string_literal: true
module
Gitlab
module
Geo
module
LogCursor
module
Events
class
DesignRepositoryUpdatedEvent
include
BaseEvent
def
process
job_id
=
unless
skippable?
registry
.
repository_updated!
schedule_job
(
event
)
end
log_event
(
job_id
)
end
private
def
registry
@registry
||=
::
Geo
::
DesignRegistry
.
safe_find_or_create_by
(
project_id:
event
.
project_id
)
end
def
schedule_job
(
event
)
enqueue_job_if_shard_healthy
(
event
)
do
::
Geo
::
DesignRepositorySyncWorker
.
perform_async
(
event
.
project_id
)
end
end
def
skippable?
Feature
.
disabled?
(
:enable_geo_design_sync
)
end
def
log_event
(
job_id
)
logger
.
event_info
(
created_at
,
'Design repository update'
,
project_id:
event
.
project_id
,
scheduled_at:
Time
.
now
,
skippable:
skippable?
,
job_id:
job_id
)
end
end
end
end
end
end
ee/spec/factories/geo/event_log.rb
View file @
eaf4cfd1
...
@@ -49,6 +49,10 @@ FactoryBot.define do
...
@@ -49,6 +49,10 @@ FactoryBot.define do
trait
:container_repository_updated_event
do
trait
:container_repository_updated_event
do
container_repository_updated_event
factory: :geo_container_repository_updated_event
container_repository_updated_event
factory: :geo_container_repository_updated_event
end
end
trait
:design_repository_updated_event
do
repository_updated_event
factory: :geo_design_repository_updated_event
end
end
end
factory
:geo_repository_created_event
,
class:
Geo
::
RepositoryCreatedEvent
do
factory
:geo_repository_created_event
,
class:
Geo
::
RepositoryCreatedEvent
do
...
@@ -63,7 +67,15 @@ FactoryBot.define do
...
@@ -63,7 +67,15 @@ FactoryBot.define do
factory
:geo_repository_updated_event
,
class:
Geo
::
RepositoryUpdatedEvent
do
factory
:geo_repository_updated_event
,
class:
Geo
::
RepositoryUpdatedEvent
do
project
project
source
{
0
}
source
{
Geo
::
RepositoryUpdatedEvent
::
REPOSITORY
}
branches_affected
{
0
}
tags_affected
{
0
}
end
factory
:geo_design_repository_updated_event
,
class:
Geo
::
RepositoryUpdatedEvent
do
project
source
{
Geo
::
RepositoryUpdatedEvent
::
DESIGN
}
branches_affected
{
0
}
branches_affected
{
0
}
tags_affected
{
0
}
tags_affected
{
0
}
end
end
...
...
ee/spec/lib/gitlab/geo/log_cursor/events/design_repository_updated_event_spec.rb
0 → 100644
View file @
eaf4cfd1
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
Geo
::
LogCursor
::
Events
::
DesignRepositoryUpdatedEvent
,
:clean_gitlab_redis_shared_state
do
include
::
EE
::
GeoHelpers
let_it_be
(
:secondary
)
{
create
(
:geo_node
)
}
let
(
:logger
)
{
Gitlab
::
Geo
::
LogCursor
::
Logger
.
new
(
described_class
,
Logger
::
INFO
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:event
)
{
create
(
:geo_design_repository_updated_event
,
project:
project
)
}
let
(
:event_log
)
{
create
(
:geo_event_log
,
repository_updated_event:
event
)
}
let!
(
:event_log_state
)
{
create
(
:geo_event_log_state
,
event_id:
event_log
.
id
-
1
)
}
subject
{
described_class
.
new
(
event
,
Time
.
now
,
logger
)
}
around
do
|
example
|
Sidekiq
::
Testing
.
fake!
{
example
.
run
}
end
before
do
stub_current_geo_node
(
secondary
)
end
shared_examples
'DesignRepositoryUpdatedEvent'
do
it
'creates a new registry when a design registry does not exist'
do
expect
{
subject
.
process
}.
to
change
(
Geo
::
DesignRegistry
,
:count
).
by
(
1
)
end
it
'marks registry as pending when a design registry exists'
do
registry
=
create
(
:geo_design_registry
,
:synced
,
project:
project
)
expect
{
subject
.
process
}.
to
change
{
registry
.
reload
.
state
}.
from
(
'synced'
).
to
(
'pending'
)
end
end
describe
'#process'
do
context
'when the feature flag is disabled'
do
before
do
stub_feature_flags
(
enable_geo_design_sync:
false
)
end
it
'does not create a design registry'
do
expect
{
subject
.
process
}.
not_to
change
(
Geo
::
DesignRegistry
,
:count
)
end
it
'does not schedule a Geo::DesignRepositorySyncWorker job'
do
expect
(
Geo
::
DesignRepositorySyncWorker
).
not_to
receive
(
:perform_async
).
with
(
project
.
id
)
subject
.
process
end
end
context
'when the feature flag is disabled'
do
before
do
stub_feature_flags
(
enable_geo_design_sync:
true
)
end
context
'when the associated shard is healthy'
do
before
do
allow
(
Gitlab
::
ShardHealthCache
).
to
receive
(
:healthy_shard?
).
with
(
'default'
).
and_return
(
true
)
end
it_behaves_like
'DesignRepositoryUpdatedEvent'
it
'schedules a Geo::DesignRepositorySyncWorker'
do
expect
(
Geo
::
DesignRepositorySyncWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
).
once
subject
.
process
end
end
context
'when associated shard is unhealthy'
do
before
do
allow
(
Gitlab
::
ShardHealthCache
).
to
receive
(
:healthy_shard?
).
with
(
'default'
).
and_return
(
false
)
end
it_behaves_like
'DesignRepositoryUpdatedEvent'
it
'does not schedule a Geo::DesignRepositorySyncWorker job'
do
expect
(
Geo
::
DesignRepositorySyncWorker
).
not_to
receive
(
:perform_async
).
with
(
project
.
id
)
subject
.
process
end
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