diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-02-28 14:07:04 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-03-03 14:57:47 +0300 |
commit | 2b27a98db32d788796c4495f5405ba09436fd8ce (patch) | |
tree | 117472736dba3c4978aa30f8cee5cba3873b5bcb /lib/gitlab/workhorse.rb | |
parent | 859a9cd9a65a2b862145efafd8716613fda29cd7 (diff) |
Add support for Workhorse notifications
Diffstat (limited to 'lib/gitlab/workhorse.rb')
-rw-r--r-- | lib/gitlab/workhorse.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb index 3ff9f9eb5e7..ca4eba48a8b 100644 --- a/lib/gitlab/workhorse.rb +++ b/lib/gitlab/workhorse.rb @@ -8,6 +8,7 @@ module Gitlab VERSION_FILE = 'GITLAB_WORKHORSE_VERSION'.freeze INTERNAL_API_CONTENT_TYPE = 'application/vnd.gitlab-workhorse+json'.freeze INTERNAL_API_REQUEST_HEADER = 'Gitlab-Workhorse-Api-Request'.freeze + NOTIFICATION_CHANNEL = 'workhorse:notifications'.freeze # Supposedly the effective key size for HMAC-SHA256 is 256 bits, i.e. 32 # bytes https://tools.ietf.org/html/rfc4868#section-2.6 @@ -154,6 +155,19 @@ module Gitlab Rails.root.join('.gitlab_workhorse_secret') end + def ensure_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(RUNNER_NOTIFICATION_CHANNEL, payload) + value + else + redis.get(key) + end + end + end + protected def encode(hash) |