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
e94e8216
Commit
e94e8216
authored
Jun 29, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract Geo::EventStore
parent
554b53f1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
72 deletions
+86
-72
app/services/geo/event_store.rb
app/services/geo/event_store.rb
+54
-0
app/services/geo/repository_deleted_event_store.rb
app/services/geo/repository_deleted_event_store.rb
+11
-22
app/services/geo/repository_renamed_event_store.rb
app/services/geo/repository_renamed_event_store.rb
+7
-25
app/services/geo/repository_updated_event_store.rb
app/services/geo/repository_updated_event_store.rb
+14
-25
No files found.
app/services/geo/event_store.rb
0 → 100644
View file @
e94e8216
module
Geo
# Base class for event store classes.
#
# Each store should also specify its event type by calling
# `self.event_type = ...` in the body of the class. The value of
# this method should be a symbol such as `:repository_updated_event`
# or `:repository_deleted_event`. For example:
#
# class RepositoryUpdatedEventStore < EventStore
# self.event_type = :repository_updated_event
# end
#
# The event type is used to determine which attribute we should set
# on an instance of the Geo::EventLog class.
#
# Event store classes should implement the instance method `build_event`.
# The `build_event` method is supposed to return an instance of the event
# that will be logged.
class
EventStore
class
<<
self
attr_accessor
:event_type
end
attr_reader
:project
,
:params
def
initialize
(
project
,
params
=
{})
@project
=
project
@params
=
params
end
def
create
return
unless
Gitlab
::
Geo
.
primary?
Geo
::
EventLog
.
transaction
do
event_log
=
Geo
::
EventLog
.
new
event_log
.
public_send
(
"
#{
self
.
class
.
event_type
}
="
,
build_event
)
event_log
.
save!
end
rescue
ActiveRecord
::
RecordInvalid
,
NoMethodError
log
(
"
#{
self
.
event_type
.
to_s
.
humanize
}
could not be created"
)
end
private
def
build_event
raise
NotImplementedError
,
"
#{
self
.
class
}
does not implement
#{
__method__
}
"
end
def
log
(
message
)
Rails
.
logger
.
error
(
"
#{
self
.
class
.
name
}
:
#{
message
}
for project
#{
project
.
path_with_namespace
}
(
#{
project
.
id
}
)"
)
end
end
end
app/services/geo/repository_deleted_event_store.rb
View file @
e94e8216
module
Geo
class
RepositoryDeletedEventStore
attr_reader
:project
,
:repo_path
,
:wiki_path
class
RepositoryDeletedEventStore
<
EventStore
self
.
event_type
=
:repository_deleted_event
def
initialize
(
project
,
repo_path
:,
wiki_path
:)
@project
=
project
@repo_path
=
repo_path
@wiki_path
=
wiki_path
end
def
create
return
unless
Gitlab
::
Geo
.
primary?
private
Geo
::
EventLog
.
transaction
do
event_log
=
Geo
::
EventLog
.
new
deleted_event
=
Geo
::
RepositoryDeletedEvent
.
new
(
project:
project
,
repository_storage_name:
project
.
repository
.
storage
,
repository_storage_path:
project
.
repository_storage_path
,
deleted_path:
repo_path
,
deleted_wiki_path:
wiki_path
,
deleted_project_name:
project
.
name
)
event_log
.
repository_deleted_event
=
deleted_event
event_log
.
save
end
def
build_event
Geo
::
RepositoryDeletedEvent
.
new
(
project:
project
,
repository_storage_name:
project
.
repository
.
storage
,
repository_storage_path:
project
.
repository_storage_path
,
deleted_path:
params
.
fetch
(
:repo_path
),
deleted_wiki_path:
params
.
fetch
(
:wiki_path
),
deleted_project_name:
project
.
name
)
end
end
end
app/services/geo/repository_renamed_event_store.rb
View file @
e94e8216
module
Geo
class
RepositoryRenamedEventStore
attr_reader
:project
,
:old_path
,
:old_path_with_namespace
def
initialize
(
project
,
old_path
:,
old_path_with_namespace
:)
@project
=
project
@old_path
=
old_path
@old_path_with_namespace
=
old_path_with_namespace
end
def
create
return
unless
Gitlab
::
Geo
.
primary?
Geo
::
EventLog
.
transaction
do
event_log
=
Geo
::
EventLog
.
new
event_log
.
repository_renamed_event
=
build_event
event_log
.
save!
end
rescue
ActiveRecord
::
RecordInvalid
log
(
"Renamed event could not be created"
)
end
class
RepositoryRenamedEventStore
<
EventStore
self
.
event_type
=
:repository_renamed_event
private
...
...
@@ -31,11 +13,15 @@ module Geo
new_path_with_namespace:
project
.
full_path
,
old_wiki_path_with_namespace:
old_wiki_path_with_namespace
,
new_wiki_path_with_namespace:
new_wiki_path_with_namespace
,
old_path:
old_path
,
old_path:
params
.
fetch
(
:old_path
)
,
new_path:
project
.
path
)
end
def
old_path_with_namespace
params
.
fetch
(
:old_path_with_namespace
)
end
def
old_wiki_path_with_namespace
"
#{
old_path_with_namespace
}
.wiki"
end
...
...
@@ -43,9 +29,5 @@ module Geo
def
new_wiki_path_with_namespace
project
.
wiki
.
path_with_namespace
end
def
log
(
message
)
Rails
.
logger
.
info
(
"
#{
self
.
class
.
name
}
:
#{
message
}
for project
#{
project
.
path_with_namespace
}
(
#{
project
.
id
}
)"
)
end
end
end
app/services/geo/repository_updated_event_store.rb
View file @
e94e8216
module
Geo
class
RepositoryUpdatedEventStore
attr_reader
:project
,
:source
,
:refs
,
:changes
def
initialize
(
project
,
refs:
[],
changes:
[],
source:
Geo
::
RepositoryUpdatedEvent
::
REPOSITORY
)
@project
=
project
@refs
=
refs
@changes
=
changes
@source
=
source
end
def
create
return
unless
Gitlab
::
Geo
.
primary?
Geo
::
EventLog
.
transaction
do
event_log
=
Geo
::
EventLog
.
new
event_log
.
repository_updated_event
=
build_event
event_log
.
save!
end
rescue
ActiveRecord
::
RecordInvalid
log
(
"
#{
Geo
::
PushEvent
.
sources
.
key
(
source
).
humanize
}
updated event could not be created"
)
end
class
RepositoryUpdatedEventStore
<
EventStore
self
.
event_type
=
:repository_updated_event
private
...
...
@@ -35,6 +16,18 @@ module Geo
)
end
def
refs
params
.
fetch
(
:refs
,
[])
end
def
changes
params
.
fetch
(
:changes
,
[])
end
def
source
params
.
fetch
(
:source
,
Geo
::
RepositoryUpdatedEvent
::
REPOSITORY
)
end
def
ref
refs
.
first
if
refs
.
length
==
1
end
...
...
@@ -54,9 +47,5 @@ module Geo
def
push_remove_branch?
changes
.
any?
{
|
change
|
Gitlab
::
Git
.
branch_ref?
(
change
[
:ref
])
&&
Gitlab
::
Git
.
blank_ref?
(
change
[
:after
])
}
end
def
log
(
message
)
Rails
.
logger
.
info
(
"
#{
self
.
class
.
name
}
:
#{
message
}
for project
#{
project
.
path_with_namespace
}
(
#{
project
.
id
}
)"
)
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