forked from cloudfoundry-attic/nsync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_client.go
37 lines (29 loc) · 1.01 KB
/
service_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package nsync
import (
"time"
"code.cloudfoundry.org/clock"
"code.cloudfoundry.org/consuladapter"
"code.cloudfoundry.org/lager"
"code.cloudfoundry.org/locket"
"github.com/tedsuo/ifrit"
)
const NysncBulkerLockSchemaKey = "nsync_bulker_lock"
func NysncBulkerLockSchemaPath() string {
return locket.LockSchemaPath(NysncBulkerLockSchemaKey)
}
type ServiceClient interface {
NewNsyncBulkerLockRunner(logger lager.Logger, bulkerID string, retryInterval, lockTTL time.Duration) ifrit.Runner
}
type serviceClient struct {
consulClient consuladapter.Client
clock clock.Clock
}
func NewServiceClient(consulClient consuladapter.Client, clock clock.Clock) ServiceClient {
return serviceClient{
consulClient: consulClient,
clock: clock,
}
}
func (c serviceClient) NewNsyncBulkerLockRunner(logger lager.Logger, bulkerID string, retryInterval, lockTTL time.Duration) ifrit.Runner {
return locket.NewLock(logger, c.consulClient, NysncBulkerLockSchemaPath(), []byte(bulkerID), c.clock, retryInterval, lockTTL)
}