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
66062c09
Commit
66062c09
authored
Sep 05, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring Gitlab::Geo::LogCursor::Daemon
parent
8026bb93
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
49 deletions
+48
-49
lib/gitlab/geo/log_cursor/daemon.rb
lib/gitlab/geo/log_cursor/daemon.rb
+47
-49
spec/lib/gitlab/geo/log_cursor/daemon_spec.rb
spec/lib/gitlab/geo/log_cursor/daemon_spec.rb
+1
-0
No files found.
lib/gitlab/geo/log_cursor/daemon.rb
View file @
66062c09
...
@@ -65,11 +65,11 @@ module Gitlab
...
@@ -65,11 +65,11 @@ module Gitlab
next
unless
can_replay?
(
event_log
)
next
unless
can_replay?
(
event_log
)
if
event_log
.
repository_updated_event
if
event_log
.
repository_updated_event
handle_repository_update
(
event_log
)
handle_repository_update
d
(
event_log
)
elsif
event_log
.
repository_created_event
elsif
event_log
.
repository_created_event
handle_repository_created
(
event_log
)
handle_repository_created
(
event_log
)
elsif
event_log
.
repository_deleted_event
elsif
event_log
.
repository_deleted_event
handle_repository_delete
(
event_log
)
handle_repository_delete
d
(
event_log
)
elsif
event_log
.
repositories_changed_event
elsif
event_log
.
repositories_changed_event
handle_repositories_changed
(
event_log
.
repositories_changed_event
)
handle_repositories_changed
(
event_log
.
repositories_changed_event
)
elsif
event_log
.
repository_renamed_event
elsif
event_log
.
repository_renamed_event
...
@@ -107,95 +107,93 @@ module Gitlab
...
@@ -107,95 +107,93 @@ module Gitlab
end
end
def
handle_repository_created
(
event_log
)
def
handle_repository_created
(
event_log
)
created_event
=
event_log
.
repository_created_event
event
=
event_log
.
repository_created_event
registry
=
::
Geo
::
ProjectRegistry
.
find_or_initialize_by
(
project_id:
created_event
.
project_id
)
registry
=
find_or_initialize_registry
(
event
.
project_id
,
resync_repository:
true
,
resync_wiki:
event
.
wiki_path
.
present?
)
registry
.
resync_repository
=
true
registry
.
resync_wiki
=
created_event
.
wiki_path
.
present?
log_event_info
(
log_event_info
(
event_log
.
created_at
,
event_log
.
created_at
,
message:
'Repository created'
,
message:
'Repository created'
,
project_id:
created_
event
.
project_id
,
project_id:
event
.
project_id
,
repo_path:
created_
event
.
repo_path
,
repo_path:
event
.
repo_path
,
wiki_path:
created_
event
.
wiki_path
,
wiki_path:
event
.
wiki_path
,
resync_repository:
registry
.
resync_repository
,
resync_repository:
registry
.
resync_repository
,
resync_wiki:
registry
.
resync_wiki
)
resync_wiki:
registry
.
resync_wiki
)
registry
.
save!
registry
.
save!
end
def
handle_repository_update
(
event
)
updated_event
=
event
.
repository_updated_event
registry
=
::
Geo
::
ProjectRegistry
.
find_or_initialize_by
(
project_id:
updated_event
.
project_id
)
case
updated_event
.
source
when
'repository'
registry
.
resync_repository
=
true
when
'wiki'
registry
.
resync_wiki
=
true
end
end
def
handle_repository_updated
(
event_log
)
event
=
event_log
.
repository_updated_event
registry
=
find_or_initialize_registry
(
event
.
project_id
,
"resync_
#{
event
.
source
}
"
=>
true
)
log_event_info
(
log_event_info
(
event
.
created_at
,
event
_log
.
created_at
,
message:
"Repository update"
,
message:
'Repository update'
,
project_id:
updated_
event
.
project_id
,
project_id:
event
.
project_id
,
source:
updated_
event
.
source
,
source:
event
.
source
,
resync_repository:
registry
.
resync_repository
,
resync_repository:
registry
.
resync_repository
,
resync_wiki:
registry
.
resync_wiki
)
resync_wiki:
registry
.
resync_wiki
)
registry
.
save!
registry
.
save!
end
end
def
handle_repository_delete
(
event
)
def
handle_repository_deleted
(
event_log
)
deleted_event
=
event
.
repository_deleted_event
event
=
event_log
.
repository_deleted_event
full_path
=
File
.
join
(
deleted_event
.
repository_storage_path
,
deleted_event
.
deleted_path
)
full_path
=
File
.
join
(
event
.
repository_storage_path
,
event
.
deleted_path
)
job_id
=
::
Geo
::
RepositoryDestroyService
job_id
=
::
Geo
::
RepositoryDestroyService
.
new
(
deleted_event
.
project_id
,
.
new
(
event
.
project_id
,
event
.
deleted_project_name
,
full_path
,
event
.
repository_storage_name
)
deleted_event
.
deleted_project_name
,
full_path
,
deleted_event
.
repository_storage_name
)
.
async_execute
.
async_execute
log_event_info
(
event
.
created_at
,
message:
"Deleted project"
,
log_event_info
(
event_log
.
created_at
,
project_id:
deleted_event
.
project_id
,
message:
'Deleted project'
,
project_id:
event
.
project_id
,
full_path:
full_path
,
full_path:
full_path
,
job_id:
job_id
)
job_id:
job_id
)
# No need to create a project entry if it doesn't exist
# No need to create a project entry if it doesn't exist
::
Geo
::
ProjectRegistry
.
where
(
project_id:
deleted_
event
.
project_id
).
delete_all
::
Geo
::
ProjectRegistry
.
where
(
project_id:
event
.
project_id
).
delete_all
end
end
def
handle_repositories_changed
(
changed_
event
)
def
handle_repositories_changed
(
event
)
return
unless
Gitlab
::
Geo
.
current_node
.
id
==
changed_
event
.
geo_node_id
return
unless
Gitlab
::
Geo
.
current_node
.
id
==
event
.
geo_node_id
job_id
=
::
Geo
::
RepositoriesCleanUpWorker
.
perform_in
(
1
.
hour
,
changed_
event
.
geo_node_id
)
job_id
=
::
Geo
::
RepositoriesCleanUpWorker
.
perform_in
(
1
.
hour
,
event
.
geo_node_id
)
if
job_id
if
job_id
log_info
(
'Scheduled repositories clean up for Geo node'
,
geo_node_id:
changed_
event
.
geo_node_id
,
job_id:
job_id
)
log_info
(
'Scheduled repositories clean up for Geo node'
,
geo_node_id:
event
.
geo_node_id
,
job_id:
job_id
)
else
else
log_error
(
'Could not schedule repositories clean up for Geo node'
,
geo_node_id:
changed_
event
.
geo_node_id
)
log_error
(
'Could not schedule repositories clean up for Geo node'
,
geo_node_id:
event
.
geo_node_id
)
end
end
end
end
def
handle_repository_rename
(
event
)
def
handle_repository_rename
(
event
_log
)
renamed_event
=
event
.
repository_renamed_event
event
=
event_log
.
repository_renamed_event
return
unless
renamed_
event
.
project_id
return
unless
event
.
project_id
old_path
=
renamed_
event
.
old_path_with_namespace
old_path
=
event
.
old_path_with_namespace
new_path
=
renamed_
event
.
new_path_with_namespace
new_path
=
event
.
new_path_with_namespace
job_id
=
::
Geo
::
MoveRepositoryService
job_id
=
::
Geo
::
MoveRepositoryService
.
new
(
renamed_event
.
project_id
,
""
,
old_path
,
new_path
)
.
new
(
event
.
project_id
,
''
,
old_path
,
new_path
)
.
async_execute
.
async_execute
log_event_info
(
event
.
created_at
,
log_event_info
(
event
_log
.
created_at
,
message:
"Renaming project"
,
message:
'Renaming project'
,
project_id:
renamed_
event
.
project_id
,
project_id:
event
.
project_id
,
old_path:
old_path
,
old_path:
old_path
,
new_path:
new_path
,
new_path:
new_path
,
job_id:
job_id
)
job_id:
job_id
)
end
end
def
find_or_initialize_registry
(
project_id
,
attrs
)
registry
=
::
Geo
::
ProjectRegistry
.
find_or_initialize_by
(
project_id:
project_id
)
registry
.
assign_attributes
(
attrs
)
registry
end
def
cursor_delay
(
created_at
)
def
cursor_delay
(
created_at
)
(
Time
.
now
-
created_at
).
to_f
.
round
(
3
)
(
Time
.
now
-
created_at
).
to_f
.
round
(
3
)
end
end
...
...
spec/lib/gitlab/geo/log_cursor/daemon_spec.rb
View file @
66062c09
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Geo
::
LogCursor
::
Daemon
,
:postgresql
do
describe
Gitlab
::
Geo
::
LogCursor
::
Daemon
,
:postgresql
do
include
::
EE
::
GeoHelpers
include
::
EE
::
GeoHelpers
...
...
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