summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2017-03-06 11:44:45 +0100
committerKamil Trzcinski <ayufan@ayufan.eu>2017-03-06 11:44:45 +0100
commit2d652fcf5a1c801c11ce11414f21234d409315f4 (patch)
tree90b291705a5f54fe0e75e1f983e1377d993a7243
parent3f5191de6db80872e3e712247b5582bdc4eec296 (diff)
downloadgitlab-ce-2d652fcf5a1c801c11ce11414f21234d409315f4.tar.gz
Update notification code
-rw-r--r--app/models/ci/runner.rb10
-rw-r--r--lib/gitlab/workhorse.rb5
-rw-r--r--spec/lib/gitlab/workhorse_spec.rb6
3 files changed, 9 insertions, 12 deletions
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb
index 34ffc4b77fc..edd21f984c8 100644
--- a/app/models/ci/runner.rb
+++ b/app/models/ci/runner.rb
@@ -127,17 +127,15 @@ 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,
- expire: RUNNER_QUEUE_EXPIRY_TIME, overwrite: false)
- end
+ new_value = SecureRandom.hex
+ ::Gitlab::Workhorse.set_key_and_notify(runner_queue_key, new_value,
+ expire: RUNNER_QUEUE_EXPIRY_TIME, overwrite: false)
end
def is_runner_queue_value_latest?(value)
diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb
index 34fbb227f7b..eae1a0abf06 100644
--- a/lib/gitlab/workhorse.rb
+++ b/lib/gitlab/workhorse.rb
@@ -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)
diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb
index 2f0db9616ed..33b6bc57e13 100644
--- a/spec/lib/gitlab/workhorse_spec.rb
+++ b/spec/lib/gitlab/workhorse_spec.rb
@@ -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