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
4bab5728
Commit
4bab5728
authored
Feb 16, 2016
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Send authentication tokens for Geo nodes update notify
Try not to loose data when REST requests fail
parent
45b39f6b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
8 deletions
+28
-8
app/services/geo/notify_nodes_service.rb
app/services/geo/notify_nodes_service.rb
+28
-8
No files found.
app/services/geo/notify_nodes_service.rb
View file @
4bab5728
...
...
@@ -2,6 +2,7 @@ module Geo
class
NotifyNodesService
<
Geo
::
BaseService
include
HTTParty
BATCH_SIZE
=
250
QUEUE
=
'updated_projects'
# HTTParty timeout
default_timeout
Gitlab
.
config
.
gitlab
.
webhook_timeout
...
...
@@ -11,7 +12,7 @@ module Geo
end
def
execute
queue_size
=
@redis
.
llen
(
'updated_projects'
)
queue_size
=
@redis
.
llen
(
QUEUE
)
return
if
queue_size
==
0
if
queue_size
>
BATCH_SIZE
...
...
@@ -21,13 +22,17 @@ module Geo
end
projects
=
[]
@redis
.
multi
do
|
redis
|
projects
=
redis
.
lrange
(
0
,
batch_size
-
1
)
redis
.
ltrim
(
0
,
batch_size
-
1
)
@redis
.
multi
do
projects
=
@redis
.
lrange
(
QUEUE
,
0
,
batch_size
-
1
)
@redis
.
ltrim
(
QUEUE
,
0
,
batch_size
-
1
)
end
::
Gitlab
::
Geo
.
secondary_nodes
.
each
do
|
node
|
notify_updated_projects
(
node
,
projects
.
value
)
success
,
message
=
notify_updated_projects
(
node
,
projects
.
value
)
unless
success
Rails
.
logger
.
error
(
"Gitlab Failed to notify
#{
node
.
url
}
:
#{
message
}
"
)
reenqueue_projects
(
projects
.
value
)
end
end
end
...
...
@@ -38,11 +43,26 @@ module Geo
body:
{
projects:
projects
}.
to_json
,
headers:
{
'Content-Type'
=>
'application/json'
,
'
X-Gitlab-Geo-Event'
=>
'Update Repositories'
'
PRIVATE-TOKEN'
=>
private_token
})
# TODO: Authentication
[(
response
.
code
>=
200
&&
response
.
code
<
300
),
ActionView
::
Base
.
full_sanitizer
.
sanitize
(
response
.
to_s
)]
return
[(
response
.
code
>=
200
&&
response
.
code
<
300
),
ActionView
::
Base
.
full_sanitizer
.
sanitize
(
response
.
to_s
)]
rescue
HTTParty
::
Error
=>
e
return
[
false
,
ActionView
::
Base
.
full_sanitizer
.
sanitize
(
e
.
message
)]
end
def
private_token
# TODO: should we ask admin user to be defined as part of configuration?
@private_token
||=
User
.
find_by
(
admin:
true
).
authentication_token
end
def
reenqueue_projects
(
projects
)
@redis
.
pipelined
do
projects
.
each
do
|
project
|
# enqueue again to the head of the queue
@redis
.
lpush
(
QUEUE
,
project
)
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