Skip to content

Commit 0b9ff3d

Browse files
authored
Make session heartbeat timeout customizable (#930)
1 parent f4fba53 commit 0b9ff3d

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

internal/session.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,14 @@ type (
6060
// ExecutionTimeout: required, no default
6161
// Specifies the maximum amount of time the session can run
6262
// CreationTimeout: required, no default
63-
// Specfifies how long session creation can take before returning an error
63+
// Specifies how long session creation can take before returning an error
64+
// HeartbeatTimeout: optional, default 20s
65+
// Specifies the heartbeat timeout. If heartbeat is not received by server
66+
// within the timeout, the session will be declared as failed
6467
SessionOptions struct {
6568
ExecutionTimeout time.Duration
6669
CreationTimeout time.Duration
70+
HeartbeatTimeout time.Duration
6771
}
6872

6973
recreateSessionParams struct {
@@ -117,7 +121,8 @@ const (
117121

118122
errTooManySessionsMsg string = "too many outstanding sessions"
119123

120-
sessionHeartBeatTimeout time.Duration = time.Second * 10
124+
defaultSessionHeartBeatTimeout time.Duration = time.Second * 20
125+
maxSessionHeartBeatInterval time.Duration = time.Second * 10
121126
)
122127

123128
var (
@@ -300,11 +305,15 @@ func createSession(ctx Context, creationTasklist string, options *SessionOptions
300305
},
301306
}
302307

308+
heartbeatTimeout := defaultSessionHeartBeatTimeout
309+
if options.HeartbeatTimeout != time.Duration(0) {
310+
heartbeatTimeout = options.HeartbeatTimeout
311+
}
303312
ao := ActivityOptions{
304313
TaskList: creationTasklist,
305314
ScheduleToStartTimeout: options.CreationTimeout,
306315
StartToCloseTimeout: options.ExecutionTimeout,
307-
HeartbeatTimeout: sessionHeartBeatTimeout,
316+
HeartbeatTimeout: heartbeatTimeout,
308317
}
309318
if retryable {
310319
ao.RetryPolicy = retryPolicy
@@ -400,7 +409,11 @@ func sessionCreationActivity(ctx context.Context, sessionID string) error {
400409
}
401410

402411
activityEnv := getActivityEnv(ctx)
403-
ticker := time.NewTicker(activityEnv.heartbeatTimeout / 2)
412+
heartbeatInterval := activityEnv.heartbeatTimeout / 3
413+
if heartbeatInterval > maxSessionHeartBeatInterval {
414+
heartbeatInterval = maxSessionHeartBeatInterval
415+
}
416+
ticker := time.NewTicker(heartbeatInterval)
404417
defer ticker.Stop()
405418

406419
for {

workflow/session.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ type (
3636
// ExecutionTimeout: required, no default
3737
// Specifies the maximum amount of time the session can run
3838
// CreationTimeout: required, no default
39-
// Specfifies how long session creation can take before returning an error
39+
// Specifies how long session creation can take before returning an error
40+
// HeartbeatTimeout: optional, default 20s
41+
// Specifies the heartbeat timeout. If heartbeat is not received by server
42+
// within the timeout, the session will be declared as failed
4043
SessionOptions = internal.SessionOptions
4144
)
4245

0 commit comments

Comments
 (0)