mirror of https://github.com/shunfei/cronsun
bugfix:单机单进程模式下锁没正确释放
parent
8794fd12b9
commit
fb673f65e0
|
@ -86,6 +86,12 @@ func (c *Client) Grant(ttl int64) (*client.LeaseGrantResponse, error) {
|
|||
return c.Client.Grant(ctx, ttl)
|
||||
}
|
||||
|
||||
func (c *Client) Revoke(id client.LeaseID) (*client.LeaseRevokeResponse, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), c.reqTimeout)
|
||||
defer cancel()
|
||||
return c.Client.Revoke(ctx, id)
|
||||
}
|
||||
|
||||
func (c *Client) KeepAliveOnce(id client.LeaseID) (*client.LeaseKeepAliveResponse, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), c.reqTimeout)
|
||||
defer cancel()
|
||||
|
|
10
job.go
10
job.go
|
@ -91,7 +91,6 @@ type locker struct {
|
|||
kind int
|
||||
ttl int64
|
||||
lID client.LeaseID
|
||||
lKey string
|
||||
timer *time.Timer
|
||||
done chan struct{}
|
||||
}
|
||||
|
@ -121,12 +120,8 @@ func (l *locker) unlock() {
|
|||
|
||||
close(l.done)
|
||||
l.timer.Stop()
|
||||
if _, err := DefalutClient.KeepAliveOnce(l.lID); err != nil {
|
||||
log.Warnf("unlock keep alive err: %s", err.Error())
|
||||
}
|
||||
err := DefalutClient.DelLock(l.lKey)
|
||||
if err != nil {
|
||||
log.Warnf("unlock[%s] err: %s", l.lKey, err.Error())
|
||||
if _, err := DefalutClient.Revoke(l.lID); err != nil {
|
||||
log.Warnf("unlock revoke err: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -270,7 +265,6 @@ func (c *Cmd) lock() *locker {
|
|||
}
|
||||
|
||||
lk.lID = resp.ID
|
||||
lk.lKey = c.Job.ID
|
||||
if lk.kind == KindAlone {
|
||||
go lk.keepAlive()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue