53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package etcd
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/RichardKnop/machinery/v2/config"
|
|
"github.com/RichardKnop/machinery/v2/locks/iface"
|
|
"github.com/RichardKnop/machinery/v2/log"
|
|
clientv3 "go.etcd.io/etcd/client/v3"
|
|
)
|
|
|
|
var (
|
|
ErrRedisLockFailed = errors.New("redis lock: failed to acquire lock")
|
|
)
|
|
|
|
type etcdLock struct {
|
|
globalConf *config.Config
|
|
conf clientv3.Config
|
|
cli *clientv3.Client
|
|
retries int
|
|
interval time.Duration
|
|
}
|
|
|
|
func New(cnf *config.Config, endpoint string) (iface.Lock, error) {
|
|
etcdConf := clientv3.Config{Endpoints: []string{endpoint}}
|
|
cli, err := clientv3.New(etcdConf)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
lock := etcdLock{
|
|
globalConf: cnf,
|
|
conf: etcdConf,
|
|
cli: cli,
|
|
}
|
|
|
|
return &lock, nil
|
|
|
|
}
|
|
|
|
func (r etcdLock) LockWithRetries(key string, unixTsToExpireNs int64) error {
|
|
err := errors.New("LockWithRetries not implemented")
|
|
log.ERROR.Print(err)
|
|
return err
|
|
}
|
|
|
|
func (r etcdLock) Lock(key string, unixTsToExpireNs int64) error {
|
|
err := errors.New("Lock not implemented")
|
|
log.ERROR.Print(err)
|
|
return err
|
|
}
|