@@ -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
123128var (
@@ -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 {
0 commit comments