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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
2d652fcf
Commit
2d652fcf
authored
Mar 06, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update notification code
parent
3f5191de
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
12 deletions
+9
-12
app/models/ci/runner.rb
app/models/ci/runner.rb
+4
-6
lib/gitlab/workhorse.rb
lib/gitlab/workhorse.rb
+2
-3
spec/lib/gitlab/workhorse_spec.rb
spec/lib/gitlab/workhorse_spec.rb
+3
-3
No files found.
app/models/ci/runner.rb
View file @
2d652fcf
...
...
@@ -127,18 +127,16 @@ module Ci
def
tick_runner_queue
SecureRandom
.
hex
.
tap
do
|
new_update
|
::
Gitlab
::
Workhorse
.
ensure
_and_notify
(
runner_queue_key
,
new_update
,
::
Gitlab
::
Workhorse
.
set_key
_and_notify
(
runner_queue_key
,
new_update
,
expire:
RUNNER_QUEUE_EXPIRY_TIME
,
overwrite:
true
)
end
end
def
ensure_runner_queue_value
Gitlab
::
Redis
.
with
do
|
redis
|
new_value
=
SecureRandom
.
hex
::
Gitlab
::
Workhorse
.
ensure
_and_notify
(
runner_queue_key
,
new_value
,
::
Gitlab
::
Workhorse
.
set_key
_and_notify
(
runner_queue_key
,
new_value
,
expire:
RUNNER_QUEUE_EXPIRY_TIME
,
overwrite:
false
)
end
end
def
is_runner_queue_value_latest?
(
value
)
ensure_runner_queue_value
==
value
if
value
.
present?
...
...
lib/gitlab/workhorse.rb
View file @
2d652fcf
...
...
@@ -155,12 +155,11 @@ module Gitlab
Rails
.
root
.
join
(
'.gitlab_workhorse_secret'
)
end
def
ensure
_and_notify
(
key
,
value
,
expire:
nil
,
overwrite:
true
)
def
set_key
_and_notify
(
key
,
value
,
expire:
nil
,
overwrite:
true
)
Gitlab
::
Redis
.
with
do
|
redis
|
result
=
redis
.
set
(
key
,
value
,
ex:
expire
,
nx:
!
overwrite
)
if
result
payload
=
"
#{
key
}
=
#{
value
}
"
redis
.
publish
(
NOTIFICATION_CHANNEL
,
payload
)
redis
.
publish
(
NOTIFICATION_CHANNEL
,
"
#{
key
}
=
#{
value
}
"
)
value
else
redis
.
get
(
key
)
...
...
spec/lib/gitlab/workhorse_spec.rb
View file @
2d652fcf
...
...
@@ -200,11 +200,11 @@ describe Gitlab::Workhorse, lib: true do
end
end
describe
'.
ensure
_and_notify'
do
describe
'.
set_key
_and_notify'
do
let
(
:key
)
{
'test-key'
}
let
(
:value
)
{
'test-value'
}
subject
{
described_class
.
ensure
_and_notify
(
key
,
value
,
overwrite:
overwrite
)
}
subject
{
described_class
.
set_key
_and_notify
(
key
,
value
,
overwrite:
overwrite
)
}
shared_examples
'set and notify'
do
it
'set and return the same value'
do
...
...
@@ -245,7 +245,7 @@ describe Gitlab::Workhorse, lib: true do
is_expected
.
to
eq
(
old_value
)
end
it
'
set and
notify'
do
it
'
does not
notify'
do
expect_any_instance_of
(
Redis
).
not_to
receive
(
:publish
)
subject
...
...
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