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.04 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"
"github.com/cloudfoundry-incubator/consuladapter"
"github.com/cloudfoundry-incubator/locket"
"github.com/pivotal-golang/clock"
"github.com/pivotal-golang/lager"
"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)
}