Skip to content

Commit d8ce2bd

Browse files
authored
Merge pull request #277 from cschleiden/ignore-poll-interval
Ignore polling interval for redis backend
2 parents e57502c + 1545d5f commit d8ce2bd

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

bench/main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ func main() {
4848

4949
wo := worker.DefaultOptions
5050
wo.WorkflowExecutorCacheSize = *cacheSize
51+
52+
if *b == "redis" {
53+
wo.ActivityPollingInterval = 0
54+
wo.WorkflowPollingInterval = 0
55+
}
56+
5157
w := worker.New(ba, &wo)
5258

5359
w.RegisterWorkflow(Root)
@@ -150,7 +156,10 @@ func getBackend(b string, opt ...backend.BackendOption) backend.Backend {
150156
ReadTimeout: time.Second * 30,
151157
})
152158

153-
rclient.FlushAll(context.Background()).Result()
159+
_, err := rclient.FlushAll(context.Background()).Result()
160+
if err != nil {
161+
panic(err)
162+
}
154163

155164
b, err := redis.NewRedisBackend(rclient, redis.WithBackendOptions(opt...))
156165
if err != nil {

internal/worker/worker.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,20 @@ func (w *Worker[Task, TaskResult]) WaitForCompletion() error {
8080
func (w *Worker[Task, TaskResult]) poller(ctx context.Context) {
8181
defer w.pollersWg.Done()
8282

83-
ticker := time.NewTicker(w.options.PollingInterval)
84-
defer ticker.Stop()
83+
var ticker *time.Ticker
84+
85+
if w.options.PollingInterval > 0 {
86+
ticker = time.NewTicker(w.options.PollingInterval)
87+
defer ticker.Stop()
88+
}
8589

8690
for {
91+
select {
92+
case <-ctx.Done():
93+
return
94+
default:
95+
}
96+
8797
task, err := w.poll(ctx, 30*time.Second)
8898
if err != nil {
8999
w.logger.ErrorContext(ctx, "error polling task", "error", err)
@@ -92,10 +102,12 @@ func (w *Worker[Task, TaskResult]) poller(ctx context.Context) {
92102
continue // check for new tasks right away
93103
}
94104

95-
select {
96-
case <-ticker.C:
97-
case <-ctx.Done():
98-
return
105+
if w.options.PollingInterval > 0 {
106+
select {
107+
case <-ticker.C:
108+
case <-ctx.Done():
109+
return
110+
}
99111
}
100112
}
101113
}

0 commit comments

Comments
 (0)