Skip to content

Commit 96a6026

Browse files
authored
Merge branch 'main' into copilot/fix-400
2 parents a1655c1 + 57fcb9a commit 96a6026

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

backend/options.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,22 @@ func WithWorkerName(workerName string) BackendOption {
124124
}
125125
}
126126

127+
// WithWorkflowLockTimeout sets the timeout for workflow task locks. If a workflow task is not completed
128+
// within this timeframe, it's considered abandoned and another worker might pick it up.
129+
func WithWorkflowLockTimeout(timeout time.Duration) BackendOption {
130+
return func(o *Options) {
131+
o.WorkflowLockTimeout = timeout
132+
}
133+
}
134+
135+
// WithActivityLockTimeout sets the timeout for activity task locks. If an activity task is not completed
136+
// within this timeframe, it's considered abandoned and another worker might pick it up.
137+
func WithActivityLockTimeout(timeout time.Duration) BackendOption {
138+
return func(o *Options) {
139+
o.ActivityLockTimeout = timeout
140+
}
141+
}
142+
127143
func ApplyOptions(opts ...BackendOption) *Options {
128144
options := DefaultOptions
129145

backend/options_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package backend
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestWithWorkflowLockTimeout(t *testing.T) {
11+
timeout := 5 * time.Minute
12+
option := WithWorkflowLockTimeout(timeout)
13+
14+
opts := ApplyOptions(option)
15+
16+
assert.Equal(t, timeout, opts.WorkflowLockTimeout)
17+
}
18+
19+
func TestWithActivityLockTimeout(t *testing.T) {
20+
timeout := 3 * time.Minute
21+
option := WithActivityLockTimeout(timeout)
22+
23+
opts := ApplyOptions(option)
24+
25+
assert.Equal(t, timeout, opts.ActivityLockTimeout)
26+
}
27+
28+
func TestWithWorkflowAndActivityLockTimeout(t *testing.T) {
29+
workflowTimeout := 2 * time.Minute
30+
activityTimeout := 4 * time.Minute
31+
32+
opts := ApplyOptions(
33+
WithWorkflowLockTimeout(workflowTimeout),
34+
WithActivityLockTimeout(activityTimeout),
35+
)
36+
37+
assert.Equal(t, workflowTimeout, opts.WorkflowLockTimeout)
38+
assert.Equal(t, activityTimeout, opts.ActivityLockTimeout)
39+
}
40+
41+
func TestDefaultValues(t *testing.T) {
42+
opts := ApplyOptions()
43+
44+
// Verify default values are preserved when no options are provided
45+
assert.Equal(t, time.Minute, opts.WorkflowLockTimeout)
46+
assert.Equal(t, time.Minute*2, opts.ActivityLockTimeout)
47+
}
48+
49+
// TestIntegrationWithOtherOptions ensures the new timeout functions can be combined with existing options
50+
func TestIntegrationWithOtherOptions(t *testing.T) {
51+
workflowTimeout := 30 * time.Second
52+
activityTimeout := 45 * time.Second
53+
stickyTimeout := 10 * time.Second
54+
maxHistorySize := int64(5000)
55+
56+
opts := ApplyOptions(
57+
WithWorkflowLockTimeout(workflowTimeout),
58+
WithActivityLockTimeout(activityTimeout),
59+
WithStickyTimeout(stickyTimeout),
60+
WithMaxHistorySize(maxHistorySize),
61+
)
62+
63+
assert.Equal(t, workflowTimeout, opts.WorkflowLockTimeout)
64+
assert.Equal(t, activityTimeout, opts.ActivityLockTimeout)
65+
assert.Equal(t, stickyTimeout, opts.StickyTimeout)
66+
assert.Equal(t, maxHistorySize, opts.MaxHistorySize)
67+
}

docs/source/includes/_backends.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
There are three backend implementations maintained in this repository. Some backend implementations have custom options and all of them accept:
44

55
- `WithStickyTimeout(timeout time.Duration)` - Set the timeout for sticky tasks. Defaults to 30 seconds
6+
- `WithWorkflowLockTimeout(timeout time.Duration)` - Set the timeout for workflow task locks. Defaults to 1 minute
7+
- `WithActivityLockTimeout(timeout time.Duration)` - Set the timeout for activity task locks. Defaults to 2 minutes
68
- `WithLogger(logger *slog.Logger)` - Set the logger implementation
79
- `WithMetrics(client metrics.Client)` - Set the metrics client
810
- `WithTracerProvider(tp trace.TracerProvider)` - Set the OpenTelemetry tracer provider

0 commit comments

Comments
 (0)