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
2547f41f
Commit
2547f41f
authored
Mar 15, 2016
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code for Bulk Notification of enqueued wiki changes
parent
47d4ede2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
13 deletions
+31
-13
app/models/geo_node.rb
app/models/geo_node.rb
+5
-1
app/services/geo/notify_nodes_service.rb
app/services/geo/notify_nodes_service.rb
+17
-10
spec/models/geo_node_spec.rb
spec/models/geo_node_spec.rb
+9
-2
No files found.
app/models/geo_node.rb
View file @
2547f41f
...
...
@@ -52,10 +52,14 @@ class GeoNode < ActiveRecord::Base
self
.
relative_url_root
=
new_uri
.
path
!=
'/'
?
new_uri
.
path
:
''
end
def
notify_url
def
notify_
projects_
url
URI
.
join
(
uri
,
"
#{
uri
.
path
}
/"
,
"api/
#{
API
::
API
.
version
}
/geo/refresh_projects"
).
to_s
end
def
notify_wikis_url
URI
.
join
(
uri
,
"
#{
uri
.
path
}
/"
,
"api/
#{
API
::
API
.
version
}
/geo/refresh_wikis"
).
to_s
end
def
oauth_callback_url
URI
.
join
(
uri
,
"
#{
uri
.
path
}
/"
,
'oauth/geo/callback'
).
to_s
end
...
...
app/services/geo/notify_nodes_service.rb
View file @
2547f41f
...
...
@@ -6,26 +6,33 @@ module Geo
default_timeout
Gitlab
.
config
.
gitlab
.
webhook_timeout
def
initialize
@queue
=
Gitlab
::
Geo
::
UpdateQueue
.
new
(
'updated_projects'
)
@proj_queue
=
Gitlab
::
Geo
::
UpdateQueue
.
new
(
'updated_projects'
)
@wiki_queue
=
Gitlab
::
Geo
::
UpdateQueue
.
new
(
'updated_wikis'
)
end
def
execute
return
if
@queue
.
empty?
projects
=
@queue
.
fetch_batched_data
process
(
@proj_queue
,
:notify_projects_url
)
process
(
@wiki_queue
,
:notify_wikis_url
)
end
private
def
process
(
queue
,
notify_url_method
)
return
if
queue
.
empty?
projects
=
queue
.
fetch_batched_data
::
Gitlab
::
Geo
.
secondary_nodes
.
each
do
|
node
|
success
,
message
=
notify_updated_projects
(
node
,
projects
)
notify_url
=
node
.
send
(
notify_url_method
.
to_sym
)
success
,
message
=
notify
(
notify_url
,
projects
)
unless
success
Rails
.
logger
.
error
(
"GitLab failed to notify
#{
node
.
url
}
:
#{
message
}
"
)
@
queue
.
store_batched_data
(
projects
)
Rails
.
logger
.
error
(
"GitLab failed to notify
#{
node
.
url
}
to
#{
notify_url
}
:
#{
message
}
"
)
queue
.
store_batched_data
(
projects
)
end
end
end
private
def
notify_updated_projects
(
node
,
projects
)
response
=
self
.
class
.
post
(
node
.
notify_url
,
def
notify
(
notify_url
,
projects
)
response
=
self
.
class
.
post
(
notify_url
,
body:
{
projects:
projects
}.
to_json
,
headers:
{
'Content-Type'
=>
'application/json'
,
...
...
spec/models/geo_node_spec.rb
View file @
2547f41f
...
...
@@ -147,14 +147,21 @@ describe GeoNode, type: :model do
end
end
describe
'#notify_url'
do
describe
'#notify_
projects_
url'
do
let
(
:refresh_url
)
{
'https://localhost:3000/gitlab/api/v3/geo/refresh_projects'
}
it
'returns api url based on node uri'
do
expect
(
new_node
.
notify_url
).
to
eq
(
refresh_url
)
expect
(
new_node
.
notify_
projects_
url
).
to
eq
(
refresh_url
)
end
end
describe
'#notify_wikis_url'
do
let
(
:refresh_url
)
{
'https://localhost:3000/gitlab/api/v3/geo/refresh_wikis'
}
it
'returns api url based on node uri'
do
expect
(
new_node
.
notify_wikis_url
).
to
eq
(
refresh_url
)
end
end
describe
'#oauth_callback_url'
do
let
(
:oauth_callback_url
)
{
'https://localhost:3000/gitlab/oauth/geo/callback'
}
...
...
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