2015-10-31 18:56:49 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015 Gravitational, Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2015-08-22 15:17:48 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2015-10-05 14:33:25 +00:00
|
|
|
"github.com/gravitational/teleport/lib/backend"
|
2015-08-22 15:17:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type LockService struct {
|
|
|
|
backend backend.Backend
|
|
|
|
}
|
|
|
|
|
2015-08-24 14:15:12 +00:00
|
|
|
func NewLockService(backend backend.Backend) *LockService {
|
|
|
|
return &LockService{backend}
|
|
|
|
}
|
|
|
|
|
2015-08-22 15:17:48 +00:00
|
|
|
// Grab a lock that will be released automatically in ttl time
|
|
|
|
func (s *LockService) AcquireLock(token string, ttl time.Duration) error {
|
2015-09-14 22:40:34 +00:00
|
|
|
return s.backend.AcquireLock(token, ttl)
|
2015-08-22 15:17:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *LockService) ReleaseLock(token string) error {
|
2015-09-14 22:40:34 +00:00
|
|
|
return s.backend.ReleaseLock(token)
|
2015-08-22 15:17:48 +00:00
|
|
|
}
|