Add with_lease to session [ci skip]
This commit is contained in:
parent
e9c14918e5
commit
2b7d759afd
1 changed files with 31 additions and 7 deletions
|
@ -26,6 +26,8 @@ module Mattermost
|
|||
include Doorkeeper::Helpers::Controller
|
||||
include HTTParty
|
||||
|
||||
LEASE_TIMEOUT = 60
|
||||
|
||||
base_uri Settings.mattermost.host
|
||||
|
||||
attr_accessor :current_resource_owner, :token
|
||||
|
@ -35,14 +37,16 @@ module Mattermost
|
|||
end
|
||||
|
||||
def with_session
|
||||
raise NoSessionError unless create
|
||||
with_lease do
|
||||
raise NoSessionError unless create
|
||||
|
||||
begin
|
||||
yield self
|
||||
rescue Errno::ECONNREFUSED
|
||||
raise NoSessionError
|
||||
ensure
|
||||
destroy
|
||||
begin
|
||||
yield self
|
||||
rescue Errno::ECONNREFUSED
|
||||
raise NoSessionError
|
||||
ensure
|
||||
destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -130,5 +134,25 @@ module Mattermost
|
|||
response.headers['token']
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue