From 7b7c1afe1b4ee3880b7d7f10fa56ddc579e640d6 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Wed, 7 Jan 2015 14:27:29 -0800 Subject: [PATCH] command/exec: Use TTL for local and foreign --- command/exec.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/command/exec.go b/command/exec.go index d1bddd3f43..404319b6fa 100644 --- a/command/exec.go +++ b/command/exec.go @@ -43,9 +43,8 @@ const ( // before assuming the job is done. rExecQuietWait = 2 * time.Second - // rExecForeignTTL is how long we default the session TTL - // to when doing an exec in a foreign DC. - rExecForeignTTL = "15s" + // rExecTTL is how long we default the session TTL to + rExecTTL = "15s" // rExecRenewInterval is how often we renew the session TTL // when doing an exec in a foreign DC. @@ -441,15 +440,18 @@ func (conf *rExecConf) validate() error { // createSession is used to create a new session for this command func (c *ExecCommand) createSession() (string, error) { + var id string + var err error if c.conf.foreignDC { - id, err := c.createSessionForeign() - if err == nil { - c.stopCh = make(chan struct{}) - go c.renewSession(id, c.stopCh) - } - return id, err + id, err = c.createSessionForeign() + } else { + id, err = c.createSessionLocal() } - return c.createSessionLocal() + if err == nil { + c.stopCh = make(chan struct{}) + go c.renewSession(id, c.stopCh) + } + return id, err } // createSessionLocal is used to create a new session in a local datacenter @@ -459,6 +461,7 @@ func (c *ExecCommand) createSessionLocal() (string, error) { se := consulapi.SessionEntry{ Name: "Remote Exec", Behavior: consulapi.SessionBehaviorDelete, + TTL: rExecTTL, } id, _, err := session.Create(&se, nil) return id, err @@ -489,7 +492,7 @@ func (c *ExecCommand) createSessionForeign() (string, error) { Node: node, Checks: []string{}, Behavior: consulapi.SessionBehaviorDelete, - TTL: rExecForeignTTL, + TTL: rExecTTL, } id, _, err := session.CreateNoChecks(&se, nil) return id, err