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
9ba1c009
Commit
9ba1c009
authored
Mar 18, 2016
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RefreshKey endpoint, worker and service
parent
5fcaad9d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
3 deletions
+61
-3
app/services/geo/schedule_key_change_service.rb
app/services/geo/schedule_key_change_service.rb
+14
-0
app/workers/geo_key_refresh_worker.rb
app/workers/geo_key_refresh_worker.rb
+36
-0
lib/api/geo.rb
lib/api/geo.rb
+11
-3
No files found.
app/services/geo/schedule_key_change_service.rb
0 → 100644
View file @
9ba1c009
module
Geo
class
ScheduleKeyChangeService
attr_reader
:id
,
:action
def
initialize
(
key_change
)
@id
=
key_change
[
'id'
]
@action
=
key_change
[
'action'
]
end
def
execute
GeoKeyRefreshWorker
.
perform_async
(
project
[
'id'
],
project
[
'clone_url'
])
end
end
end
app/workers/geo_key_refresh_worker.rb
0 → 100644
View file @
9ba1c009
class
GeoKeyRefreshWorker
include
Sidekiq
::
Worker
sidekiq_options
queue: :default
,
retry:
55
sidekiq_retry_in
do
|
count
|
count
<=
30
?
linear_backoff_strategy
(
count
)
:
geometric_backoff_strategy
(
count
)
end
def
perform
(
key_id
,
action
)
action
=
action
.
to_sym
case
action
when
:create
# ActiveRecord::RecordNotFound when not found (so job will retry)
key
=
Key
.
find
(
key_id
)
key
.
add_to_shell
when
:delete
# ActiveRecord::RecordNotFound when not found (so job will retry)
key
=
Key
.
find
(
key_id
)
key
.
remove_from_shell
end
end
private
def
linear_backoff_strategy
(
count
)
rand
(
1
..
20
)
+
count
end
def
geometric_backoff_strategy
(
count
)
# This strategy is based on the original one from sidekiq
count
=
count
-
30
# we must start counting after 30
(
count
**
4
)
+
15
+
(
rand
(
30
)
*
(
count
+
1
))
end
end
lib/api/geo.rb
View file @
9ba1c009
...
...
@@ -3,12 +3,11 @@ module API
before
{
authenticated_as_admin!
}
resource
:geo
do
# Enqueue a batch of IDs of modified projects to have their
# repositories updated
#
# Example request:
# POST /refresh_projects
# POST /
geo/
refresh_projects
post
'refresh_projects'
do
required_attributes!
[
:projects
]
::
Geo
::
ScheduleRepoUpdateService
.
new
(
params
[
:projects
]).
execute
...
...
@@ -18,11 +17,20 @@ module API
# wiki repositories updated
#
# Example request:
# POST /refresh_wikis
# POST /
geo/
refresh_wikis
post
'refresh_wikis'
do
required_attributes!
[
:projects
]
::
Geo
::
ScheduleWikiRepoUpdateService
.
new
(
params
[
:projects
]).
execute
end
# Enqueue a change operation for specific key ID
#
# Example request:
# POST /geo/refresh_key
post
'refresh_key'
do
required_attributes!
[
:key_change
]
::
Geo
::
ScheduleKeyChangeService
.
new
(
params
[
:key_change
]).
execute
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