Skip to content

Commit

Permalink
refactor: use github.com/coreos/etcd/clientv3
Browse files Browse the repository at this point in the history
  • Loading branch information
kl7sn committed Aug 27, 2020
1 parent f13436b commit 2ed39de
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 84 deletions.
10 changes: 3 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,22 @@ require (
github.com/garyburd/redigo v1.6.0
github.com/go-resty/resty/v2 v2.2.0
github.com/google/btree v1.0.1-0.20191016161528-479b5e81b0a9 // indirect
github.com/gorilla/websocket v1.4.0 // indirect
github.com/jinzhu/gorm v1.9.12
github.com/json-iterator/go v1.1.10
github.com/labstack/echo/v4 v4.1.16
github.com/labstack/gommon v0.3.0
github.com/nats-io/nats-server/v2 v2.1.6 // indirect
github.com/nats-io/nats.go v1.9.2
github.com/rfyiamcool/go-shell v0.0.0-20200724023351-26f4635eb56d
github.com/robfig/cron/v3 v3.0.1
github.com/shunfei/cronsun v0.3.5 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.6.1
github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6 // indirect
github.com/uber-go/atomic v1.4.0
github.com/yangchenxing/go-nginx-conf-parser v0.0.0-20190110023421-0d59f1b7a3f6
go.etcd.io/etcd v0.5.0-alpha.5.0.20200425165423-262c93980547
go.etcd.io/bbolt v1.3.4 // indirect
go.uber.org/zap v1.15.0
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
google.golang.org/grpc v1.29.0
gopkg.in/ini.v1 v1.56.0
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

Expand Down
127 changes: 74 additions & 53 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pkg/job/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package job

import (
"fmt"

"github.com/douyu/juno-agent/pkg/job/parser"
"github.com/douyu/juno-agent/pkg/report"
"github.com/robfig/cron/v3"

"github.com/douyu/jupiter/pkg/conf"
"github.com/douyu/jupiter/pkg/xlog"
"github.com/robfig/cron/v3"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion pkg/job/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ package job

import (
"fmt"
"go.uber.org/zap"
"runtime"
"sync/atomic"
"time"

"github.com/douyu/jupiter/pkg/util/xstring"
"github.com/douyu/jupiter/pkg/xlog"
"github.com/robfig/cron/v3"
"go.uber.org/zap"
)

type (
Expand Down
11 changes: 2 additions & 9 deletions pkg/job/etcd/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ package etcd

import (
"context"
"go.etcd.io/etcd/clientv3"
"time"

"go.etcd.io/etcd/clientv3/concurrency"
"github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/clientv3/concurrency"
)

// Mutex ...
Expand Down Expand Up @@ -47,13 +47,6 @@ func (mutex *Mutex) Lock(timeout time.Duration) (err error) {
return mutex.m.Lock(ctx)
}

// TryLock ...
func (mutex *Mutex) TryLock(timeout time.Duration) (err error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return mutex.m.TryLock(ctx)
}

// Unlock ...
func (mutex *Mutex) Unlock() (err error) {
err = mutex.m.Unlock(context.TODO())
Expand Down
6 changes: 3 additions & 3 deletions pkg/job/etcd/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ package etcd

import (
"context"
"github.com/douyu/jupiter/pkg/client/etcdv3"
"sync"

"github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/mvcc/mvccpb"
"github.com/douyu/jupiter/pkg/client/etcdv3"
"github.com/douyu/jupiter/pkg/ecode"
"github.com/douyu/jupiter/pkg/util/xgo"
"github.com/douyu/jupiter/pkg/xlog"
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/mvcc/mvccpb"
)

// Watch A watch only tells the latest revision
Expand Down
4 changes: 2 additions & 2 deletions pkg/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"syscall"
"time"

"github.com/coreos/etcd/clientv3/concurrency"
"github.com/douyu/juno-agent/pkg/job/etcd"
"github.com/douyu/jupiter/pkg/xlog"
"go.etcd.io/etcd/clientv3/concurrency"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -247,7 +247,7 @@ func (c *Cmd) Run() error {
c.logger.Info("job get lock error : ", xlog.FieldErr(err))
return err
}
err = mutex.TryLock(time.Duration(c.ReqTimeout) * time.Second)
err = mutex.Lock(time.Duration(c.ReqTimeout) * time.Second)
if err != nil {
c.logger.Info("job lock is failed : ", xlog.FieldErr(err))
return err
Expand Down
3 changes: 2 additions & 1 deletion pkg/job/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package parser

import (
"fmt"
"github.com/robfig/cron/v3"
"math"
"strconv"
"strings"
"time"

"github.com/robfig/cron/v3"
)

// Configuration options for creating a parser. Most options specify which
Expand Down
8 changes: 4 additions & 4 deletions pkg/job/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"encoding/json"
"fmt"
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/clientv3/concurrency"
"strings"
"sync/atomic"
"time"

"github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/clientv3/concurrency"
)

// 当前执行中的任务信息
Expand Down Expand Up @@ -49,7 +50,7 @@ func GetProcFromKey(key string) (proc *Process, err error) {
}

func (p *Process) Key() string {
return ProcKeyPrefix + p.NodeID + "/" + p.JobID + "/" + p.ID
return ProcKeyPrefix + p.NodeID + "/" + p.JobID + "/" + p.ID
}

func (p *Process) Val() (string, error) {
Expand All @@ -75,7 +76,6 @@ func (p *Process) put(job *Job) (err error) {
return err
}


ctx, cancel := context.WithTimeout(context.Background(),
time.Duration(job.ReqTimeout)*time.Second)
defer cancel()
Expand Down
4 changes: 2 additions & 2 deletions pkg/job/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"strconv"
"syscall"

"github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/mvcc/mvccpb"
"github.com/douyu/juno-agent/pkg/job/etcd"
"github.com/douyu/jupiter/pkg/client/etcdv3"
"github.com/douyu/jupiter/pkg/util/xgo"
"github.com/douyu/jupiter/pkg/xlog"
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/mvcc/mvccpb"
)

// Node 执行 cron 命令服务的结构体
Expand Down

0 comments on commit 2ed39de

Please sign in to comment.