mirror of
https://github.com/status-im/consul.git
synced 2025-01-14 07:44:50 +00:00
command/exec: Use TTL for local and foreign
This commit is contained in:
parent
ce83322e16
commit
7b7c1afe1b
@ -43,9 +43,8 @@ const (
|
|||||||
// before assuming the job is done.
|
// before assuming the job is done.
|
||||||
rExecQuietWait = 2 * time.Second
|
rExecQuietWait = 2 * time.Second
|
||||||
|
|
||||||
// rExecForeignTTL is how long we default the session TTL
|
// rExecTTL is how long we default the session TTL to
|
||||||
// to when doing an exec in a foreign DC.
|
rExecTTL = "15s"
|
||||||
rExecForeignTTL = "15s"
|
|
||||||
|
|
||||||
// rExecRenewInterval is how often we renew the session TTL
|
// rExecRenewInterval is how often we renew the session TTL
|
||||||
// when doing an exec in a foreign DC.
|
// 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
|
// createSession is used to create a new session for this command
|
||||||
func (c *ExecCommand) createSession() (string, error) {
|
func (c *ExecCommand) createSession() (string, error) {
|
||||||
|
var id string
|
||||||
|
var err error
|
||||||
if c.conf.foreignDC {
|
if c.conf.foreignDC {
|
||||||
id, err := c.createSessionForeign()
|
id, err = c.createSessionForeign()
|
||||||
if err == nil {
|
} else {
|
||||||
c.stopCh = make(chan struct{})
|
id, err = c.createSessionLocal()
|
||||||
go c.renewSession(id, c.stopCh)
|
|
||||||
}
|
|
||||||
return id, err
|
|
||||||
}
|
}
|
||||||
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
|
// 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{
|
se := consulapi.SessionEntry{
|
||||||
Name: "Remote Exec",
|
Name: "Remote Exec",
|
||||||
Behavior: consulapi.SessionBehaviorDelete,
|
Behavior: consulapi.SessionBehaviorDelete,
|
||||||
|
TTL: rExecTTL,
|
||||||
}
|
}
|
||||||
id, _, err := session.Create(&se, nil)
|
id, _, err := session.Create(&se, nil)
|
||||||
return id, err
|
return id, err
|
||||||
@ -489,7 +492,7 @@ func (c *ExecCommand) createSessionForeign() (string, error) {
|
|||||||
Node: node,
|
Node: node,
|
||||||
Checks: []string{},
|
Checks: []string{},
|
||||||
Behavior: consulapi.SessionBehaviorDelete,
|
Behavior: consulapi.SessionBehaviorDelete,
|
||||||
TTL: rExecForeignTTL,
|
TTL: rExecTTL,
|
||||||
}
|
}
|
||||||
id, _, err := session.CreateNoChecks(&se, nil)
|
id, _, err := session.CreateNoChecks(&se, nil)
|
||||||
return id, err
|
return id, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user