Merge branch 'zj-mattermost-slash-config' of gitlab.com:gitlab-org/gitlab-ce into zj-mattermost-slash-config

This commit is contained in:
Z.J. van de Weg 2016-12-20 20:14:27 +01:00
commit 0bd8669f3a
2 changed files with 34 additions and 7 deletions

3
lib/mattermost/error.rb Normal file
View file

@ -0,0 +1,3 @@
module Mattermost
class Error < StandardError; end
end

View file

@ -26,6 +26,8 @@ module Mattermost
include Doorkeeper::Helpers::Controller include Doorkeeper::Helpers::Controller
include HTTParty include HTTParty
LEASE_TIMEOUT = 60
base_uri Settings.mattermost.host base_uri Settings.mattermost.host
attr_accessor :current_resource_owner, :token attr_accessor :current_resource_owner, :token
@ -35,14 +37,16 @@ module Mattermost
end end
def with_session def with_session
raise NoSessionError unless create with_lease do
raise NoSessionError unless create
begin begin
yield self yield self
rescue Errno::ECONNREFUSED rescue Errno::ECONNREFUSED
raise NoSessionError raise NoSessionError
ensure ensure
destroy destroy
end
end end
end end
@ -130,5 +134,25 @@ module Mattermost
response.headers['token'] response.headers['token']
end end
end end
def with_lease
lease_uuid = lease_try_obtain
raise NoSessionError unless lease_uuid
begin
yield
ensure
Gitlab::ExclusiveLease.cancel(lease_key, lease_uuid)
end
end
def lease_key
"mattermost:session"
end
def lease_try_obtain
lease = ::Gitlab::ExclusiveLease.new(lease_key, timeout: LEASE_TIMEOUT)
lease.try_obtain
end
end end
end end