Skip to content

Commit

Permalink
add flag of ttl for lock cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhou committed Aug 5, 2017
1 parent 366f538 commit 989a955
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion etcdctl/ctlv3/command/lock_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ import (
"golang.org/x/net/context"
)

var (
sessionTTL int
defaultSessionTTL = 10
)

// NewLockCommand returns the cobra command for "lock".
func NewLockCommand() *cobra.Command {
c := &cobra.Command{
Use: "lock <lockname> [exec-command arg1 arg2 ...]",
Short: "Acquires a named lock",
Run: lockCommandFunc,
}
c.Flags().IntVarP(&sessionTTL, "session-ttl", "t", defaultSessionTTL, "timeout for session")
return c
}

Expand All @@ -49,7 +55,7 @@ func lockCommandFunc(cmd *cobra.Command, args []string) {
}

func lockUntilSignal(c *clientv3.Client, lockname string, cmdArgs []string) error {
s, err := concurrency.NewSession(c)
s, err := concurrency.NewSession(c, concurrency.WithTTL(sessionTTL))
if err != nil {
return err
}
Expand Down

0 comments on commit 989a955

Please sign in to comment.