diff options
author | Rémy Coutable <remy@rymai.me> | 2017-03-07 00:39:56 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-03-07 00:39:56 +0000 |
commit | ef24c9ef775218adfdb8178fdc9a3bf4016a53b0 (patch) | |
tree | 192a213ba0a62890867eadc47df53816c03cfd15 /lib | |
parent | d12c992191c0b3941b4cabb36f059b798dd20a35 (diff) | |
parent | 8ab17a5305e666cdeba59a01a57ff47df77f2c0a (diff) | |
download | gitlab-ce-ef24c9ef775218adfdb8178fdc9a3bf4016a53b0.tar.gz |
Merge branch 'use-publish-to-post-notifications' into 'master'
Use publish channel to post notifications changes
See merge request !9574
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/workhorse.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb index 3ff9f9eb5e7..eae1a0abf06 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,18 @@ module Gitlab Rails.root.join('.gitlab_workhorse_secret') end + 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 + redis.publish(NOTIFICATION_CHANNEL, "#{key}=#{value}") + value + else + redis.get(key) + end + end + end + protected def encode(hash) |