Skip to content

Commit 88031e2

Browse files
authored
Make heartbeat interval configurable
1 parent 2b5159f commit 88031e2

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

internal/worker/activity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (aw *activityWorker) handleTask(ctx context.Context, task *task.Activity) {
121121
heartbeatCtx, cancelHeartbeat := context.WithCancel(ctx)
122122

123123
go func(ctx context.Context) {
124-
t := time.NewTicker(30 * time.Second)
124+
t := time.NewTicker(aw.options.ActivityHeartbeatInterval)
125125
defer t.Stop()
126126

127127
for {

internal/worker/options.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package worker
22

3+
import "time"
4+
35
type Options struct {
46
// WorkflowsPollers is the number of pollers to start. Defaults to 2.
57
WorkflowPollers int
@@ -15,15 +17,24 @@ type Options struct {
1517
// by the worker. The default is 0 which is no limit.
1618
MaxParallelActivityTasks int
1719

20+
// ActivityHeartbeatInterval is the interval between heartbeat attempts for activity tasks. Defaults
21+
// to 25 seconds
22+
ActivityHeartbeatInterval time.Duration
23+
1824
// HeartbeatWorkflowTasks determines if the lock on workflow tasks should be periodically
1925
// extended while they are being processed. Given that workflow executions should be
2026
// very quick, this is usually not necessary.
2127
HeartbeatWorkflowTasks bool
28+
29+
// WorkflowHeartbeatInterval is the interval between heartbeat attempts on workflow tasks, when enabled.
30+
WorkflowHeartbeatInterval time.Duration
2231
}
2332

2433
var DefaultOptions = Options{
25-
WorkflowPollers: 2,
26-
ActivityPollers: 2,
27-
MaxParallelWorkflowTasks: 0,
28-
MaxParallelActivityTasks: 0,
34+
WorkflowPollers: 2,
35+
ActivityPollers: 2,
36+
MaxParallelWorkflowTasks: 0,
37+
MaxParallelActivityTasks: 0,
38+
ActivityHeartbeatInterval: 25 * time.Second,
39+
WorkflowHeartbeatInterval: 25 * time.Second,
2940
}

internal/worker/workflow.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ func (ww *workflowWorker) getExecutor(ctx context.Context, t *task.Workflow) (wo
185185
}
186186

187187
func (ww *workflowWorker) heartbeatTask(ctx context.Context, task *task.Workflow) {
188-
// TODO: Make configurable
189-
t := time.NewTicker(25 * time.Second)
188+
t := time.NewTicker(ww.options.WorkflowHeartbeatInterval)
190189
defer t.Stop()
191190

192191
for {

0 commit comments

Comments
 (0)